home *** CD-ROM | disk | FTP | other *** search
/ LSD Docs / LSD Docs.iso / FILEZ / lsd34.dms / lsd34.adf / AREXX.doc1.pp / AREXX.doc1
Text File  |  1990-09-13  |  153KB  |  3,567 lines

  1.             AREXX USER'S REFERENCE MANUAL
  2.  
  3.                                 PART 1
  4.  
  5.               TABLE OF CONTENTS
  6.  
  7.  
  8.  
  9. INTRODUCTION....................................................1
  10.  1. Organization of this Document...............................1
  11.     1 Using this Manual.........................................2
  12.     2 Typographic Conventions...................................2
  13.  2. Future Directions...........................................2
  14. CHAPTER 1. WHAT IS AREXX?.......................................3
  15.  1. Language Features...........................................3
  16.  2. ARexx on the Amiga..........................................4
  17.  3. Further Information.........................................4
  18. CHAPTER 2. GETTING ACQUAINTED...................................5
  19.  1. Installing ARexx............................................5
  20.     1 ARexx and Workbench.......................................5
  21.     2 Installation..............................................5
  22.     3 Starting the Resident Process.............................6
  23.     4 Naming Conventions........................................6
  24.     5 The REXX: Directory.......................................6
  25.  2. Program Examples............................................7
  26. CHAPTER 3. ELEMENTS OF THE LANGUAGE............................11
  27.  1. Format.....................................................11
  28.  2. Tokens.....................................................11
  29.     1 Comment Tokens...........................................11
  30.     2 Symbol Tokens............................................11
  31.     3 String Tokens............................................12
  32.     4 Operators................................................12
  33.     5 Special Character Tokens.................................13
  34.  3. Clauses....................................................14
  35.     1 Null Clauses.............................................14
  36.     2 Label Clauses............................................14
  37.     3 Assignment Clauses.......................................14
  38.     4 Instruction Clauses......................................15
  39.     5 Command Clauses..........................................15
  40.     6 Clause Classification....................................15
  41.  4. Expressions................................................16
  42.     1 Symbol Resolution........................................16
  43.     2 Order of Evaluation......................................16
  44.  5. Numbers and Numeric Precision..............................17
  45.     1 Boolean Values...........................................17
  46.     2 Numeric Precision........................................17
  47.  6. Operators..................................................18
  48.     1 Arithmetic Operators.....................................18
  49.     2 Concatenation Operators..................................20
  50.     3 Comparison Operators.....................................20
  51.     4 Logical (Boolean) Operators..............................21
  52.  7. Stems and Compound Symbols.................................21
  53.  
  54.                 i
  55.  
  56. CHAPTER 3. ELEMENTS OF THE LANGUAGE (CONT).....................11
  57.  8. The Execution Environment..................................22
  58.     1 The External Environment.................................22
  59.     2 The Internal Environment.................................22
  60.     3 Input and Output.........................................23
  61.     4 Resource Tracking........................................24
  62. CHAPTER 4. INSTRUCTIONS........................................25
  63.  1. ADDRESS....................................................25
  64.  2. ARG........................................................25
  65.  3. BREAK......................................................26
  66.  4. CALL.......................................................26
  67.  5. DO.........................................................27
  68.  6. DROP.......................................................28
  69.  7. ECHO.......................................................28
  70.  8. ELSE.......................................................28
  71.  9. END........................................................29
  72.  10. EXIT......................................................29
  73.  11. IF........................................................29
  74.  12. INTERPRET.................................................30
  75.  13. ITERATE...................................................30
  76.  14. LEAVE.....................................................31
  77.  15. NOP.......................................................31
  78.  16. NUMERIC...................................................31
  79.  17. OPTIONS...................................................32
  80.  18. OTHERWISE.................................................32
  81.  19. PARSE.....................................................33
  82.      1 Input Sources...........................................33
  83.      2 Templates...............................................34
  84.  20. PROCEDURE.................................................35
  85.  21. PULL......................................................35
  86.  22. PUSH......................................................36
  87.  23. QUEUE.....................................................37
  88.  24. RETURN....................................................37
  89.  25. SAY.......................................................38
  90.  26. SELECT....................................................38
  91.  27. SHELL.....................................................38
  92.  28. SIGNAL....................................................38
  93.  29. THEN......................................................39
  94.  30. TRACE.....................................................40
  95.  31. UPPER.....................................................40
  96.  32. WHEN......................................................41
  97. CHAPTER 5. COMMANDS............................................43
  98.  1. Command Clauses............................................43
  99.  2. The Host Address...........................................44
  100.  3. The Command Interface......................................44
  101.  4. Using Commands in Macro Programs...........................45
  102.  5. Using ARexx with Command Shells............................45
  103.  6. Command Inhibition.........................................46
  104.  
  105.                 ii
  106.  
  107. CHAPTER 6. FUNCTIONS...........................................47
  108.  1. Syntax and Search Order....................................47
  109.     1 Search Order.............................................47
  110.     2 Internal Functions.......................................48
  111.     3 Built-In Functions.......................................49
  112.     4 External Function Libraries..............................49
  113.     5 Function Hosts...........................................50
  114.  2. The Built-In Function Library..............................50
  115.     1 ABBREV().................................................51
  116.     2 ABS()....................................................51
  117.     3 ADDLIB().................................................51
  118.     4 ADDRESS()................................................51
  119.     5 ARG()....................................................52
  120.     6 B2C()....................................................52
  121.     7 BITAND().................................................52
  122.     8 BITCHG().................................................52
  123.     9 BITCLR().................................................53
  124.     10 BITCOMP()...............................................53
  125.     11 BITOR().................................................53
  126.     12 BITSET()................................................53
  127.     13 BITTST()................................................53
  128.     14 BITXOR()................................................54
  129.     15 C2B()...................................................54
  130.     16 C2D()...................................................54
  131.     17 C2X()...................................................54
  132.     18 CENTER() OR CENTRE()....................................55
  133.     19 CLOSE().................................................55
  134.     20 COMPRESS()..............................................55
  135.     21 COMPARE()...............................................55
  136.     22 COPIES()................................................55
  137.     23 D2C()...................................................56
  138.     24 DATATYPE()..............................................56
  139.     25 DELSTR()................................................56
  140.     26 DELWORD()...............................................57
  141.     27 EOF()...................................................57
  142.     28 ERRORTEXT().............................................57
  143.     29 EXISTS()................................................57
  144.     30 EXPORT()................................................57
  145.     31 FREESPACE().............................................58
  146.     32 GETCLIP()...............................................58
  147.     33 GETSPACE()..............................................58
  148.     34 HASH()..................................................58
  149.     35 IMPORT()................................................59
  150.     36 INDEX().................................................59
  151.     37 INSERT()................................................59
  152.     38 LASTPOS()...............................................59
  153.     39 LEFT()..................................................60
  154.     40 LENGTH()................................................60
  155.  
  156.                 iii
  157.  
  158.     41 MAX()...................................................60
  159.     42 MIN()...................................................60
  160.     43 OPEN()..................................................60
  161.     44 OVERLAY()...............................................61
  162.     45 POS()...................................................61
  163.     46 PRAGMA()................................................61
  164.     47 RANDOM()................................................62
  165.     48 RANDU().................................................62
  166.     49 READCH()................................................62
  167.     50 READLN()................................................63
  168.     51 REMLIB()................................................63
  169.     52 REVERSE()...............................................63
  170.     53 RIGHT().................................................63
  171.     54 SEEK()..................................................63
  172.     55 SETCLIP()...............................................64
  173.     56 SHOW()..................................................64
  174.     57 SIGN()..................................................64
  175.     58 SPACE().................................................64
  176.     59 STORAGE()...............................................65
  177.     60 STRIP().................................................65
  178.     61 SUBSTR()................................................65
  179.     62 SUBWORD()...............................................66
  180.     63 SYMBOL()................................................66
  181.     64 TIME()..................................................66
  182.     65 TRACE().................................................67
  183.     66 TRANSLATE().............................................67
  184.     67 TRIM()..................................................67
  185.     68 UPPER().................................................67
  186.     69 VALUE().................................................68
  187.     70 VERIFY()................................................68
  188.     71 WORD()..................................................68
  189.     72 WORDINDEX().............................................68
  190.     73 WORDLENGTH()............................................68
  191.     74 WORDS().................................................69
  192.     75 WRITECH()...............................................69
  193.     76 WRITELN()...............................................69
  194.     77 X2C()...................................................69
  195.     78 XRANGE()................................................69
  196. CHAPTER 7. TRACING AND INTERRUPTS..............................71
  197.  1. Tracing Options............................................71
  198.  2. Display Formatting.........................................72
  199.     1 Tracing Output...........................................72
  200.     2 Command Inhibition.......................................73
  201.  3. Interactive Tracing........................................73
  202.     1 Error Processing.........................................74
  203.     2 The External Tracing Flag................................74
  204.  4. Interrupts.................................................74
  205.  
  206.                 iv
  207.  
  208. CHAPTER I. PARSING AND TEMPLATES...............................77
  209.  1. Template Structure.........................................77
  210.     1 Template Objects.........................................78
  211.     2 The Scanning Process.....................................78
  212.  2. Templates in Action........................................79
  213.     1 Parsing by Tokenization..................................79
  214.     2 Pattern Parsing..........................................80
  215.     3 Positional Markers.......................................80
  216.     4 Multiple Templates.......................................80
  217. CHAPTER 9. THE RESIDENT PROCESS................................83
  218.  1. Command Utilities..........................................83
  219.     1 HI.......................................................83
  220.     2 RX.......................................................84
  221.     3 RXSET....................................................84
  222.     4 RXC......................................................84
  223.     5 TCC......................................................84
  224.     6 TCO......................................................84
  225.     7 TE.......................................................84
  226.     8 TS.......................................................84
  227.  2. Resource Management........................................85
  228.     1 The Global Tracing Console...............................85
  229.     2 The Library List.........................................85
  230.     3 The Clip List............................................86
  231. CHAPTER 10. INTERFACING TO AREXX...............................89
  232.  1. Basic Structers............................................90
  233.  2. Designing a Command Interface..............................91
  234.     1 Receiving Command Messages...............................92
  235.     2 Result Fields............................................92
  236.     3 Multiple Host Processes..................................92
  237.  3. Invoking ARexx Programs....................................93
  238.     1 Message Packets..........................................93
  239.     2 Command Invocations......................................94
  240.     3 Function Invocations.....................................95
  241.     4 Search Order.............................................95
  242.     5 Extension Fields.........................................96
  243.     6 Interpreting the Result Fields...........................97
  244.  4. Communicating with the Resident Process....................97
  245.     1 Command (Action) Codes...................................97
  246.     2 Modifier Flags...........................................99
  247.     3 Result Fields...........................................100
  248.  5. External Function Libraries...............................100
  249.     1 Design Considerations...................................100
  250.     2 Calling Convention......................................101
  251.     3 Parameter Conversion....................................101
  252.     4 Returned Values.........................................101
  253.  6. Direct Manipulation of Data Structures....................102
  254.  
  255.                 v
  256.  
  257. APPENDIX A. ERROR MESSAGES....................................103
  258. APPENDIX B. LIMITS AND COMPATIBILITY..........................109
  259.  1 Limits.....................................................109
  260.  2 Compatibility..............................................109
  261. APPENDIX C. THE AREXX SYSTEMS LIBRARY.........................111
  262.  1 Functional Groups..........................................111
  263.  2 Library Functions..........................................113
  264. APPENDIX D. THE AREXX SUPPORT LIBRARY.........................127
  265.    1 ALLOCMEM()...............................................127
  266.    2 CLOSEPORT()..............................................127
  267.    3 FREEMEM()................................................128
  268.    4 GETARG().................................................128
  269.    5 GETPKT().................................................128
  270.    6 OPENPORT()...............................................128
  271.    7 REPLY()..................................................129
  272.    8 SHOWDIR()................................................129
  273.    9 SHOWLIST()...............................................129
  274.    10 STATEF()................................................130
  275.    11 WAITPKT()...............................................130
  276. APPENDIX E. DISTRIBUTION FILES................................131
  277.  1 Directories................................................131
  278.    1 The :C Directory.........................................131
  279.    2 The :INCLUDE Directory...................................131
  280.    3 The :LIBS Directory......................................132
  281.    4 The :REXX Directory......................................132
  282.    5 The :TOOLS Directory.....................................132
  283.    6 Miscellaneous Files......................................132
  284.  2 Listings of Header Files...................................133
  285.    1 storage.h................................................133
  286.    2 rxslib.h.................................................139
  287.    3 rexxio.h.................................................142
  288.    4 errors.h.................................................144
  289. GLOSSARY......................................................147
  290. INDEX.........................................................151
  291.  
  292.                 vi
  293.  
  294.                INTRODUCTION
  295.  
  296. Welcome to ARexx,an implementation of the REXX language for the Amiga computer.
  297. ARexx is a powerful programming took,but one which by virtue of its clean
  298. syntax and sparse vocabulary is also easy to learn and easy to use.
  299.  
  300. 1 ORGANIZATION OF THIS DOCUMENT
  301.  
  302. This document will attempt to fill the roles of User's Manual,Language
  303. Reference,and Programmer's Guide. The chapters that follow have been organized
  304. to provide a gently introduction to the language.
  305.  
  306. Chapter 1,What is ARexx?,gives an overview of the ARexx language and its
  307. implementation of the Amiga.
  308.  
  309. Chapter 2,Getting Acquainted,tells how to install ARexx on your Amiga and
  310. presents several example programs to illustrate the features of the language.
  311.  
  312. Chapter 3,Elements of the Language,introduces the language structure and
  313. syntax.
  314.  
  315. Chapter 4,Instructions,describes the action statements of ARexx.
  316.  
  317. Chapter 5,Commands,describes the program statements used to communicate with
  318. external programs.
  319.  
  320. Chapter 6,Functions,explains how functions are called and documents the Built-
  321. In Function library.
  322.  
  323. Chapter 7,Tracing and Interrupts,describes the source level debugging features
  324. useful for developing and testing programs.
  325.  
  326. Chapter 8,Parsing and Templates,describes the instructions used to extract
  327. words or fields from strings.
  328.  
  329. Chapter 9,The Resident Process,describes the capabilities of the global
  330. communications and resources manager.
  331.  
  332. Chapter 10,Interfacing to ARexx,describes how to design and implement an
  333. interface between ARexx and an external program.
  334.  
  335. Appendix A,Error Messages,lists the error messages issued by the interpreter.
  336.  
  337. Appendix B,Limits and Compatibility,discusses the compatibility of ARexx with
  338. the language standard.
  339.  
  340. Appendix C,The ARexx Systems Library,documents the functions of ARexx systems
  341. library.
  342.  
  343. Appendix D,The Support Library,documents the library of Amiga specific
  344. functions.
  345.  
  346. Appendix E,Distribution Files,lists the files on the distribution disk.
  347.  
  348. Finally,a Glossary and an Index are provided.
  349.  
  350.                 1
  351.  
  352. USING THIS MANUAL
  353.  
  354. If you are new to the REXX language,or perhaps to programming itself,you should
  355. review chapters 1 through 4 and then play with ARexx by running some of the
  356. sample programs given in chapter 2. Further examples are available in the :rexx
  357. directory of the distribution disk.
  358.  
  359. If you are already familiar with REXX you may wish to skip directly to chapter
  360. 5,which begins to present some of the system-dependent features of this
  361. implementation. A summary of the compatibility of ARexx with the language
  362. definition is contained in Appendix B.
  363.  
  364. TYPOGRAPHIC CONVENTIONS
  365.  
  366. Describing a language is sometimes difficult because of the multiple and
  367. changing contexts involved. To help clarify the presentation here,a simply
  368. typographic convention has been adopted throughout the document. All of the
  369. terms and words specific to the REXX language,as well as the program examples
  370. and computer input and output,have been set in typewriter font like this. This
  371. should help to distinguish the language keywords and examples from the
  372. surrounding text.
  373.  
  374. 2 FUTURE DIRECTIONS
  375.  
  376. ARexx,like most software products,will probably envolve somewhat over the next
  377. few years as new features are added,old bugs are removed,and market imperatives
  378. become more apparant. While the core language will probably undergo few
  379. modifications,many capabilities will be added to the function libraries
  380. supported by ARexx. Your comments and suggestions for improvements to ARexx are
  381. most welcome.
  382.  
  383. The author sincerely hopes that other software developers will consider using
  384. ARexx with their products. The advantages of having a rich variety of software
  385. products sharing a common user interface and a common procedural interface
  386. cannot be overstated. This is the underlying promise of the Amiga's
  387. multitasking capability,and that which most sets it apart from other
  388. inexpensive computers.
  389.  
  390. Example Programs. One of the best ways to learn a computer language is to study
  391. examples written by more experienced programmers. The ARexx distribution disk
  392. includes a few example programs in the :rexx directory,and more programs will
  393. be added in future releases.
  394.  
  395. If you have written REXX language program(for any computer)that you think would
  396. be of interest to a more general audience,please send it to the author for
  397. consideration. Programs should be of interest either in terms of their specific
  398. funtionality or as an example of programming technique. Each program submitted
  399. should include an author credit and a few lines of commentary on its intended
  400. fuction.
  401.  
  402.                 2
  403.  
  404. ARexx is a high-level language useful for prototyping,software integration,and
  405. general programming tasks. It is an implementation of the REXX language
  406. described by M.F. Cowlishaw in The REXX Language:A Practical Approach to
  407. Programming(Prentice-Hall,1985),and follow the language definition closely.
  408. ARexx is particularly well suited as a command language. Command programs,
  409. sometimes called "scripts" or "macros",are widely used to extend the predefined
  410. commands of an operating system or to customize an applications program.
  411.  
  412. As a programming language,ARexx can be useful to a wide cross section of users.
  413. For the novice programmer,ARexx is an easy-to-learn yet powerful language that
  414. serves as a good introduction to programming techniques. Its source-level
  415. debugging facilities will help take some of the mystery out of how programs
  416. work(or don't work,as is more frequently the case.)
  417.  
  418. For the more sophisticated user,ARexx provides the means to build fully
  419. integrated software packages,combining different applications programs into an
  420. environment tailored to their needs. A common command language among
  421. applications that support ARexx will bring uniformity to procedural interfaces,
  422. much as the Amiga's Intuition provides uniformity in the graphical interface.
  423.  
  424. Finally,for the software developer,ARexx offers a straightforward way to build
  425. fully programmable applications programs. Developers can concentrate their
  426. efforts on making the basic operations of their programs fast and efficient,and
  427. let the end user add the frills and custom features.
  428.  
  429. 1-1 LANGUAGE FEATURES
  430.  
  431. Some of the important features of the language are:
  432.  
  433. TYPELESS DATA. Data are treated as typeless character strings. Variables do not
  434. have to be declared before being used,and all operations dynamically check the
  435. validity of the operands.
  436.  
  437. COMMAND INTERFACE. ARexx programs can issue commands to external programs that
  438. provide a suitable command interface. Any software package that implements the
  439. command interface is then fully programmable using ARexx,and can be extended
  440. and customized by the end user.
  441.  
  442. TRACING AND DEBUGGING. ARexx includes source-level debugging facilities that
  443. allow the programmer to see the step-by-step actions of a program as it runs,
  444. thereby reducing the time required to develop and test programs. An internal
  445. interrupt system permits special handling of errors that would otherwise cause
  446. the program to terminate.
  447.  
  448.                 3
  449.  
  450. INTERPRETED EXECUTION. ARexx programs are run by an interpreter,so separate
  451. compilation and linking steps are not required. This makes it especially useful
  452. for prototyping and as a learning tool.
  453.  
  454. FUNCTION LIBRARIES. External function libraries can be used to extend the
  455. capabilities of the language or as bridges to other programs. Libraries also
  456. allow ARexx programs to be used as "test drivers" for software development and
  457. testing.
  458.  
  459. AUTOMATIC RESOURCE MANAGEMENT. Internal memory allocation related to the
  460. creation and destruction of strings and other data structures is handled
  461. automatically.
  462.  
  463. 1-2 AREXX ON THE AMIGA
  464.  
  465. ARexx was designed to run on the Amiga,and makes use of many of the features of
  466. its multitasking operating system. ARexx programs run as separate tasks and
  467. may communicate with each other or with external programs. The interpreter
  468. follows the design guidelines expected of well-behaved programs in a
  469. multitasking environment: specifcally,it uses as little memory as possible and
  470. is careful to reutrn resources to the operating system when they are no longer
  471. needed. Memory requirements were minimized by implementing the entire ARexx
  472. system as a shared library,so that only one copy of the program code must be
  473. loaded.
  474.  
  475. 1-3 FURTHER INFORMATION
  476.  
  477. The aforementioned book by M.F. Cowlishaw is highly recommended to those
  478. interested in further information about REXX. It presents an interesting
  479. discussion of the design and development of the language.
  480.  
  481.                 4
  482.  
  483.             CHAPTER 2 GETTING ACQUAINTED
  484.  
  485. This chapter explains how to install ARexx on your Amiga computer and shows
  486. some example programs.
  487.  
  488. 2-1 INSTALLING AREXX
  489.  
  490. ARexx requires an Amiga computer with at least 256k of memory,and will operate
  491. under V1.1 or V1.2 of the operating system. It uses the double-precision math
  492. library called "mathieeedoubbas.library" that is supplied with the Amiga
  493. WorkBench disk,so make sure that this file is present in your LIBS: directory.
  494. The distribution disk includes the language system,some example programs,and a
  495. set of the INCLUDE files required for integrating ARexx with other software
  496. packages. The distribution files are listed in Appendix E.
  497.  
  498. AREXX AND WORKBENCH
  499.  
  500. ARexx can be installed and loaded from within the icon-based environment
  501. provided by the Amiga WorkBench. However,it is a primarily a text-oriented
  502. language system and requires a good text editor and file management environment
  503. to be most effective. Unless you purchased ARexx as part of an applications
  504. package that includes an integrated editor,you'll probably find it useful to
  505. become familiar with the Commmand Line Interface (CLI)environment on the Amiga.
  506.  
  507. INSTALLATION
  508.  
  509. The ARexx language system consists of a shared library,a resident program,and
  510. several command utilities. All of the required files are contained in the :c
  511. and :libs directories of the distribution disk. ARexx may be installed on any
  512. of the system disks with which it will be used,but first check the :c and :libs
  513. directores of each disk to make sure that there are no naming conflicts. The
  514. following steps will then install ARexx on the system disk,provided that two
  515. disk drives are available:
  516.  
  517. 1. Activate a CLI window.
  518. 2. Copy the ARexx :libs directory to the system LIBS: directory with the
  519. command "copy df1:libs to libs:".
  520. 3. Copy the ARexx :c directory to the system C: directory with the command
  521. "copy df1:C to c:".
  522.  
  523. SINGLE DRIVE SYSTEMS. Installing software in a single-drive system can be very
  524. confusing,so an installation utility has been provided with the ARexx
  525. distribution disk. It copies the :c and :libs directories of the distribution
  526. disk into memory,and then prompts the user to insert each disk that is to
  527. receive the files. Follow these steps to run the installation utility:
  528.  
  529.                 5
  530.  
  531. 1. Activate a CLI window.
  532. 2. Insert the distribution disk into drive 0 and type "df0:rxinstall".
  533. 3. At the program prompt,insert the system disk on which ARexx is to be
  534. installed into drive 0.
  535. 4. Repeat step 3 as required.
  536.  
  537. STARTING THE RESIDENT PROCESS
  538.  
  539. ARexx programs are launched by a background program called the resident
  540. process. It can be started by issuing the command rexxmast and must be active
  541. before any ARexx programs can be run. The rexxmast program briefly displays a
  542. small window to announce itself,and then disappears into the background to
  543. await your next request. If you will be using ARexx frequently,you can place
  544. the rexxmast command in the "startup-sequence" file that resides in the system
  545. S: directory. This will start the resident process automatically when you
  546. reboot the computer.
  547.  
  548. After the resident process has been loaded,ARexx programs can be run from the
  549. CLI by typing the command rx followed by the program name and any arguments.
  550. For example,the sample program calc.rexx,which evaluates an expression,could be
  551. run by typeing "rx :rexx/calc 1+1."
  552.  
  553. You may not need to start up the resident process if you are using a software
  554. package that starts it automatically. Applications that use ARexx can test
  555. whether the resident process is active by checking for a public message port
  556. named "REXX." If the port hasn't been opened,the program can issue the rexxmast
  557. command directly.
  558.  
  559. The resident process can be closed using the command rxc;it will then exit as
  560. soon as the last ARexx program finishes execution. Unless you are very short on
  561. memory space,there is usually no reason to close ARexx,as it simply waits in
  562. the background for the next program to run.
  563.  
  564. NAMING CONVENTIONS
  565.  
  566. ARexx programs can be named anything,but adopting a simple naming convention
  567. will make managing the programs much easier. Programs to be run from the CLI
  568. are usually given the file extention .rexx to distinguish them from programs
  569. written in other languages. Programs written as "macros" or "scripts" for a
  570. particular applications program should be given a file extension specific to
  571. that program. For example,a macro written for a communications program called
  572. "MyComm" might be named "download.myc". ARexx uses this file extention when it
  573. searches for a program file to be executed. 
  574.  
  575. THE REXX: DIRECTORY
  576.  
  577. You can designate one directory as the system-wide source for ARexx programs by
  578. defining a REXX: "device" with the assign command. This directory should reside
  579. on a volume that is usually mounted,such as SYS: or a hard disk. For example,
  580. the command "assign rexx: sys:rexx" defines the REXX: device as the :rexx
  581. directory on the system disk. Once defined,the REXX: device is searched after
  582. the current directory when looking for an ARexx program.
  583.  
  584.                 6
  585.  
  586. 2-2 PROGRAM EXAMPLES
  587.  
  588. Before introducing the structure and syntax of the language,let's look at a few
  589. examples of ARexx programs. Readers familiar with other high-level programming
  590. languages should find many points of similarity between ARexx and other
  591. languages. In the examples that follow,new terms are highlighted in the text as
  592. they are introduced,and will be convered in depth in the next few chapters.
  593.  
  594. These short programs can be created using any text editor and then run from the
  595. Command Line Interface (CLI),or may simply be read as samples of the language.
  596. If the examples are to be run,first complete the installation procedures
  597. outlined in the previous section,and then start the ARexx resident process.
  598. Example programs can then be run by entering,for example,"rx age" at the CLI
  599. prompt.
  600.  
  601. We'll begin with a "Hello,World" program that simply displays a message on the
  602. console screen.
  603.  
  604.     /* A simple program */
  605.     say 'Hello,World'
  606.  
  607. This program consists of a comment line that describes the program and an
  608. instruction that displays text on the console. For historical reasons, ARexx
  609. programs begin with a comment line;the initial "/*" says "I'm an ARexx program"
  610. to the interpreter when it searches for a program.
  611.  
  612. Instructions are language statements that denote a certain action to be
  613. performed,and always start with a symbol,in this case the word say. Symbols are
  614. translated to uppercase when the program is run,so the symbol say here is
  615. equivalent to SAY. Following say is an example of a string,which is a series of
  616. characters surrounded by quotes ('). Double quotes (") could also have been
  617. used to define the string.
  618.  
  619. In the next program we'll display a prompt for input and then read some
  620. information from the user.
  621.  
  622.     /* Calculate age in days */
  623.     say 'Please enter your age'
  624.     pull age
  625.     say 'You are about' age*365 'days old'
  626.  
  627. This program uses the pull instruction to read a line of input into a variable
  628. called age,which is then used with a say instuction. Variables are symbols that
  629. may be assigned a value. The words following say form an expression in which
  630. strings are joined and an arithmetic calculation is performed.
  631.  
  632. Note that the variable age did not have to be declared as a number;instead,its
  633. value was checked when it was actually used in the expression. To see what
  634. would happen if age wasn't a number,try rerunning the program with a
  635. non-numeric entry for the age. The resulting error message shows the line
  636. number and type of error that occurred,after which the program ends.
  637.  
  638.                 7
  639.  
  640. The next program introduces the do instruction,which allows program statements
  641. to be executed repeatedly. It also illustrates the exponentiation operator,
  642. which is used to raise a number to an integral power.
  643.  
  644.     /* Calculate some squares and cubes      */
  645.     do i = 1 to 10      /* 10 interations    */
  646.        say i i**2 i**3  /* calculations      */
  647.        end
  648.     say ' all done '
  649.  
  650. The do instruction causes the statements between the do and end instructions to
  651. be executed 10 times. The variable i is the index variable for the loop,and is
  652. incremented by 1 for each iteration. The number following the symbol to is the
  653. limit for the do instruction,and could have been a full expression rather than
  654. just the constant 10. Note that the statements within the loop have been
  655. indented. This is not required by the language,but it makes the program more
  656. readable and is therefore good programming practice.
  657.  
  658. The subject of the next example is the if instruction,a often-used control
  659. statement that allows statements to be conditionally executed. The numbers from
  660. 1 to 10 are classified as even or odd by dividing them by 2 and then checking
  661. the remainder.
  662.  
  663.     /* Even or odd? */
  664.     do i = 1 to 10
  665.        if i//2 = 0 then type = 'even'
  666.                    else type = 'odd'
  667.        say i 'is' type
  668.        end
  669.  
  670. This example intoduces the // arithmetic operator,which calculates the
  671. remainder after a division operation. The if instruction tests whether the
  672. remainder is 0 and executes the then branch if it is,thereby setting the
  673. variable type to "even." If the remainder was not 0,the alternative else branch
  674. is executed and type is set to "odd."
  675.  
  676. The next example introduces the concept of a function,which is a group of
  677. statements that can be executed by mentioning the function name in a suitable
  678. context. Functions are an important part of most programming languages,as they
  679. allow large,complex programs to be built from smaller modules. Functions are
  680. specified in an expression as a name followed by an open parenthesis. One or
  681. more expressions called arguments may follow the parenthesis;these are used to
  682. pass information to the function for processing.
  683.  
  684.                 8
  685.  
  686.     /* Defining and calling a function     */
  687.     do i = 1 to 5
  688.        say i square(i)     /* call square  */
  689.        end
  690.     exit            /* all done            */
  691.     square:        /* function name       */
  692.     arg x        /* get the "argument"  */
  693.     return x**2     /* square it and return*/
  694.  
  695. The function square is defined in the lines followed the label square: up
  696. through the return instruction. Two new instructions are introduced here: arg
  697. retrieves the value of the argument string,and return passes the functon's
  698. result back to the point where the function was called.
  699.  
  700. One final example will suffice for now. A new instruction called trace is used
  701. here to activate the tracing features of ARexx.
  702.  
  703.     /* Demonstrate "results" tracing */
  704.     trace results
  705.     sum=0;sumsq=0;
  706.     do i = 1 to 5
  707.        sum = sum + i
  708.        sumsq = sumsq + i**2
  709.        end
  710.     say 'sum=' sum 'sumsq=' sumsq
  711.  
  712. When this program is run,the console displays the source lines as they are
  713. excuted,and shows the final results of expressions. This makes it easy to tell
  714. what the program is really doing,and helps reduce the time required to develop
  715. and test a new program. One minor point is illustrated here: the third line
  716. shows two distinct statements separated by a semicolon (;). The semicolon is an
  717. example of a special character,characters that have particular meanings within
  718. ARexx programs.
  719.  
  720. The following chapters will present further information on the language
  721. statements illustrated here and will introduce others that have not been shown.
  722. Take heart,though;ARexx is a "small" language and there are relatively few
  723. words and rules to learn.
  724.  
  725.                 9
  726.  
  727. THERE WAS NO PAGE 10
  728.  
  729.             ELEMENTS OF THE LANGUAGE
  730.  
  731. This chapter introduces the rules and concepts that make up the REXX language.
  732. The intent is not to present a formalized definition,but rather to convey a
  733. practical understanding of how the language elements "fit together" to form
  734. programs.
  735.  
  736. 3-1 FORMAT
  737.  
  738. ARexx programs are compossed of ASCII characters and may be created using any
  739. text editor. No special formatting of the program statements is required or
  740. imposed on the programmer.
  741.  
  742. 3-2 TOKENS
  743.  
  744. The smallest distinct entities or "words" of the language are called tokens. A
  745. token may be series of characters,as in the symbol MyName,or just a single
  746. character like the "+" operator. Tokens can be categorized into comments,
  747. symbols,strings,operators,and special characters. Each of these groups are
  748. described below.
  749.  
  750. COMMENT TOKENS
  751.  
  752. Any group of characters beginning with the sequence "/*" and ending with "*/"
  753. defines a comment token. Comments may be placed anywhere in a program and cost
  754. little in terms of execution speed,since they are stripped(removed)when the
  755. program is first scanned by the interpreter. Comments may be "nested" within
  756. one another,but each "/*" must have a matching "*/" in the program.
  757. Examples:
  758.  
  759.     /* Your basic comment       */
  760.     /* a  /* nested! */ comment */
  761.  
  762. SYMBOL TOKENS
  763.  
  764. Any group of the characters a-z,A-Z,0-9,and .!?$_defines a symbol token.
  765. Symbols are translated to uppercase as the program is scanned by the
  766. interpreter,so the symbol MyName is equivalent to MYNAME. Four types of symbols
  767. are recognized:
  768.  
  769.     Fixed symbols begin with a digit (0-9) or a period(.).
  770.     Simple symbols do not begin with a digit,and do not contain any
  771.     periods.
  772.     Stem symbols have exactly one period at the end of the symbol name.
  773.     Compound symbols include one or more periods in the interior of the
  774.     name.
  775.  
  776. Stems and compound symbols have special properties that make them useful for
  777. building arrays and lists.
  778.  
  779.                 11
  780.  
  781. SYMBOLS VALUES. The value used for a fixed symbol is always the symbol name
  782. itself(as translated to uppercase.) Simple,stem,and compound symbols are called
  783. variables and may be assigned a value;the value used for an uninitialized
  784. variable is just the variable name itself.
  785. Examples:
  786.     
  787.     123.45        /*a fixed symbol    */
  788.     MyName        /*same as MyName    */
  789.     a.        /*a stem symbol        */
  790.     a.1.Index    /*a compound symbol    */
  791.  
  792. STRING TOKENS
  793.  
  794. A group of characters beginning and ending with a quote (')or double quote(")
  795. delimiter defines a string token. The delimiter character itself may be
  796. included within the string by a double-delimiter sequence (" or ""). The number
  797. of characters in the string is called its length,and a string of length zero is
  798. called a null string. A string is treated as a literal in an expression;that
  799. is,its value is just the string itself.
  800.  
  801. Strings followed immediately by an "X" or "B" character that is not part of a
  802. longer symbol are classified as hex or binary strings,respectively,and must be
  803. composed of hexadecimal digits(0-9,A-F) or binary digits(0,1). Blanks are
  804. permitted at byte boundaries for added readability. Hex and binary strings are
  805. convenient for specifying non-ASCII characters and for machine-specific
  806. information like addresses in a program. They are converted immediately to the
  807. "packed" internal form.
  808. Examples:
  809.     "Now is the time"    /*a simple example    */
  810.     ""            /*a null string        */
  811.     'Can't you see??'    /*Can't you see??    */
  812.     '4A 3B CO'X        /*a hex string        */
  813.     '00110111'b        /*binary for '7'    */
  814.  
  815. OPERATORS
  816.  
  817. The characters  +-*/=><*| may be combined in the sequences shown in Table 3.1
  818. to form operator tokens. Operator sequences may include leading,trailing,and
  819. embedded blanks,all of which are removed when the program is scanned. In
  820. addition to the above characters,the blank character as a concatenation
  821. operator if it follows a symbol or string and is not adjacent to an operator or
  822. special character.
  823.  
  824. Each operator has an associated priority that determines the order in which
  825. operations will be performed in an expression. Operators with higher priorities
  826. before those with lower priorities.
  827.  
  828.                 12
  829.  
  830.             TABLE 3.1 OPERATOR SEQUENCES
  831.  
  832. SEQUENCE        PRIORITY        OPERATOR DEFINITION
  833.  
  834.             8            Logical NOT
  835. +            8            Prefix Conversion
  836. -            8            Prefix Negation
  837. **            7            Exponentiation
  838. *            6            Multiplication
  839. /            6            Division
  840. %            6            Integer Division
  841. //            6            Remainder
  842. +            5            Addition
  843. -            5            Subtration
  844. ||            4            Concatenation
  845. (blank)            4            Blank Concatenation
  846. ==            3            Exact Equality
  847. ~==            3            Exact Inequality
  848. =            3            Equality
  849. ~=            3            Inequality
  850. >            3            Greater Than
  851. >=,~<            3            Greater Than or Equal To
  852. <            3            Less Than
  853. <=,~>            3            Less Than or Equal To
  854. &            2            Logical AND
  855. |            1            Logical Inclusive OR
  856. ^,&&            1            Logical Exclusive OR
  857.  
  858. SPECIAL CHARACTER TOKENS
  859.  
  860. The characters :():,are each treated as a separate special character token and
  861. have particular meanings within an ARexx program. Blanks adjacent to these
  862. special characters are removed,except for those preceding an open parenthesis
  863. or following a close parenthesis.
  864.  
  865. COLON (:). A colon,if preceded by a symbol token,defines a label within the
  866. program. Lavels are locations in the program to which control may be
  867. transferred under various conditions.
  868.  
  869. OPENING AND CLOSING PARENTHESES (()). Parentheses are used in expressions to
  870. group operators and operands into subexpressions,in order to override the
  871. normal operator primorities. An open parenthesis also serves to identify a
  872. function call within an expression;a symbol or string followed immediately by
  873. an open parenthesis defines a function name. Parentheses must always be
  874. balanced within a statement.
  875.  
  876. SEMICOLON (;). The semicolon acts as a program statement terminator. Several
  877. statements may be placed on a single source line if separated by semicolons.
  878.  
  879.                 13
  880.  
  881. COMMA (,). A comma token acs as the continuation character for statements that
  882. must be entered on several source lines. It is also used to separate the
  883. argument expressions in a function call.
  884.  
  885. 3-3 CLAUSES
  886.  
  887. Tokens are grouped together to form clauses,the smallest language unit that can
  888. be executed as a statement. Every clause in ARexx can be classified as either a
  889. null,label,assignment,instruction,or command clause. The classification process
  890. is very simple,since no more than two tokens are required to classify any
  891. clause. Assignment,instruction,and command clauses are jointly termed
  892. statements.
  893.  
  894. CLAUSE CONTINUATION. The end of a source line normally acts as the implicit end
  895. of a clause. A clause can be continued on the next source line by ending the
  896. line with a comma (,). The commas is then removed,and the next line is
  897. considered as a continuation of the clause. There is no limit to the number of
  898. continuations that may occur. String and comment tokens are automatically
  899. continued if a line end before the closing delimiter has been found,and the
  900. "newline" character is not considered to be part of the token.
  901.  
  902. MULTIPLE CLAUSES. Several clauses can be placed on a single line by separating
  903. them with semicolons(;).
  904.  
  905. NULL CLAUSES
  906.  
  907. Lines consisting only of blanks or comments are called null clauses. They have
  908. no function in the execution of a program,except to aid its readability and to
  909. increment the source line count. Null clauses may appear anywhere in a program.
  910. Example:
  911.  
  912.     /* perform annuity calculations        */
  913.  
  914. LABEL CLAUSES
  915.  
  916. A symbol followed immediately by a colon defines a label clause. A label acts
  917. as a placemarker in the program,but no action occurs with the "execution" of a
  918. label. The colon is considered as an implicit clause terminator,so each label
  919. stands as a separate clause. Label clauses may appear anywhere in a program.
  920. Examples:
  921.  
  922.     start:        /* begin execution    */
  923.     syntax:        /* error processing    */
  924.  
  925. ASSIGNMENT CLAUSES
  926.  
  927. Assignments are identified by a variable symbol followed by an "=" operator. In
  928. this context the operator's normal definition(an equality comparison)is
  929. overridden,and it becomes an assignment operator. The tokens to the right of
  930. the "=" are evaluated as an expression,and the result is assigned to(becomes
  931. the value of)the variable symbol.
  932.  
  933.                 14
  934.  
  935. Examples:
  936.  
  937.     when= 'Now is the time'
  938.     answ= 3.14 * fact(5)
  939.  
  940. INSTRUCTION CLAUSES
  941.  
  942. Instructions begin with certain keyword symbols,each of which denotes a
  943. particular action to be performed. Instruction keywords are recognized as such
  944. only at the beginning of a clause,and may otherwise be used freely as symbols
  945. (although such use may become confusing at times.) The ARexx instructions are
  946. described in detail in Chapter 4. 
  947. Examples:
  948.  
  949.     drop a b c        /* reset variables    */
  950.     say 'please'        /* a polite program    */
  951.     if j > 5 then leave;    /* several instructions    */
  952.  
  953. COMMAND CLAUSES
  954.  
  955. Commands are any ARexx expression that can't be classified as one of the
  956. preceding types of clauses. The expression is evaluated and the result is
  957. issued as a command to an external host,which might be the native operating
  958. system or an application program. Commands are discussed in Chapter 5,and the
  959. details of the host command interface are given in Chapter 10.
  960. Examples:
  961.  
  962.     'delete' 'myfile'    /* a DOS command    */
  963.     'jump' current+10    /* an editor command?    */
  964.  
  965. CLAUSE CLASSIFICATION
  966.  
  967. The process by which program lines are divided into clauses and then classified
  968. is important in understanding the operation of an ARexx program. The language
  969. interpreter splits the program source into groups of clauses as the program is
  970. read,using the end of each line as a clause separator and applying the
  971. continuation rule as required. These groups of one or more clauses are then
  972. tokenized,and each clause is classified into one of the above types. Note that
  973. seemingly small syntactic differences may completely change the semantic
  974. content of a statement. For example,
  975.  
  976.     SAY 'Hello, Bill'
  977.  
  978. is an instruction clause and will display "Hello, Bill" on the console,but
  979.  
  980.     ""SAY 'Hello, Bill'
  981.  
  982. is a command clause,and will issue "SAY Hello, Bill" as a command to an
  983. external program. The presence of the leading null string changes the
  984. classification from an instruction clause to a command clause.
  985.  
  986.                 15
  987.  
  988. 3-4 EXPRESSIONS
  989.  
  990. Expression evaluation is an important part of ARexx programs,since most
  991. statements include at least one expression. Expressions are composed of
  992. strings,symbols,operators,and parentheses. Strings are used as literals in an
  993. expression;their value in an operation is just the string itself. Fixed symbols
  994. are also literals(remember that symbols are always translated to uppercase,)
  995. but variable symbols may have an assigned value. Operator tokens represent the
  996. predefined operations of ARexx;each operator has an associated priority that
  997. determines the order in which operations will be performed. Parentheses may be
  998. used to alter the normal order of evaluation in the expression,or to identify
  999. function calls. A symbol or string followed immediately by an open parenthesis
  1000. defines the function name,and the tokens between the opening and(final)closing
  1001. parenthesis form the argument list for the function.
  1002.  
  1003. For example,the expression "J 'fractorial is' fact(J)" is composed of a symbol
  1004. J,a blank operator,the string 'factorial is',another blank,the symbol fact,an
  1005. open parenthesis,the symbol J again,and a closing parenthesis. FACT is a
  1006. function name and (J) is its argument list,in this case the single expression
  1007. J.
  1008.  
  1009. SYMBOL RESOLUTION
  1010.  
  1011. Before the evaluation of an expression can proceed,the interpreter must obtain
  1012. a value for each symbol in the expression. For fixed symbols the value is just
  1013. the symbol name itself,but variable symbols must be looked up in the current
  1014. symbol table. In the example above,the expression after symbol resolution would
  1015. be "3 'factorial is' FACT(3)," assuming that the symbol J had the value 3.
  1016.  
  1017. Suppose that the example above had been "FACT(J) 'is' J 'factorial'." Would the
  1018. second occurrence of symbol J still resolve to 3 in this case? In general,
  1019. function calls may have "side effects" that include altering the values of
  1020. variables,so the value of J might have been changed by the call to FACT. In
  1021. order to avoid ambiguities in the values assigned to symbols during the
  1022. resolution process, ARexx guarantees a strict left-to-right resolution order.
  1023. Symbol resolution proceeds irrespective of operator priority or parenthetical
  1024. grouping;if a function call is found,the resolution is suspended while the
  1025. function is evaluated. Note that it is possible for the same symbol to have
  1026. more than one value in an expression.
  1027.  
  1028. ORDER OF EVALUATION
  1029.  
  1030. After all symbol values have been resolved,the expression is evaluated based on
  1031. operator priority and subexpression grouping. Operators of higher priority are
  1032. evaluated first. ARexx does not guarantee an order of evaluation among
  1033. operators of equal priority,and does not employ a "fast path" evaluation of
  1034. boolean operators. For example,in the expression
  1035.  
  1036.     (1 = 2) & (FACT(3) = 6)
  1037.  
  1038. the call to the FACT function will be made,although it is clear that the final
  1039. result will be 0,since the first term of the AND operation is 0.
  1040.  
  1041.                 16
  1042.  
  1043. 3-5 NUMBERS AND NUMERIC PRECISION
  1044.  
  1045. An important class of operands are those representing numbers. Numbers consist
  1046. of the characters 0-9,.+-,and blanks;an e or E may follow a number to indicate
  1047. exponential notation,in which case it must be followed by a (signed) integer).
  1048.  
  1049. Both string tokens and symbol tokens may be used to specify numbers. Since the
  1050. language is typeless,variables do not have to be declared as "numeric" before
  1051. being used in an arithmetic operation. Instead,each value string is examined
  1052. when it is used to verify that it represents a number. The following examples
  1053. are all valid numbers:
  1054.  
  1055.     33
  1056.     "   12.3   "
  1057.     0.321e12
  1058.     ' + 15.'
  1059.  
  1060. Note that leading and trailing blanks are permitted,and that blanks may be
  1061. embedded between a "+" or "-" sign and the number body(but not within the
  1062. body.)
  1063.  
  1064. BOOLEAN VALUES
  1065.  
  1066. The numbers 0 and 1 are used to represent the boolean values False and True,
  1067. respectively. The use of a value other than 0 or 1 when a boolean operand is
  1068. expected will generate an error. Any number equivalent to 0 or 1,for example
  1069. "0.000" or "0.1E1," is also acceptable as a boolean value.
  1070.  
  1071. NUMERIC PRECISION
  1072.  
  1073. ARexx allows the basic precision used for arithmetic calculations to be
  1074. modified while a program is executing. The number of significant figures used
  1075. in arithmetic operations is determined by the Numeric Digits environment
  1076. variable, and may be modified using the NUMERIC instruction.
  1077.  
  1078. The number of decimal places used for a result depends on the operation
  1079. performed and the number of decimal places in the operands. Unlike many
  1080. languages,ARexx preserves trailing zeroes to indicate the precision of the
  1081. result. If the total number of digits required to express a value exceeds the
  1082. current Numeric Digits setting,the number is formatted in exponential notation.
  1083. Two such formats are provided:
  1084.  
  1085. In SCIENTIFIC notation,the exponent is adjusted so that a single digit is
  1086. placed to the left of the decimal point.
  1087.  
  1088. in ENGINEERING notation,the number is scaled so that the exponent is a multiple
  1089. of 3 and the digits to the left of the decimal point range from 1 to 999.
  1090.  
  1091. The numeric precision and format can be set using the NUMERIC instruction.
  1092.  
  1093.                 17
  1094.  
  1095. 3-6 OPERATORS
  1096.  
  1097. Operators can be grouped into four categories:
  1098.  
  1099. Arithmetic operators require one or two numeric operands,and produce a numeric
  1100. result.
  1101. Concatenation operators join two strings into a single string.
  1102. Comparison operators require two operands,and produce a boolean(0 or 1) result.
  1103. Logical Operators require one or two boolean operands,and produce a boolean
  1104. result.
  1105.  
  1106. ARITHMETIC OPERATORS
  1107.  
  1108. The aritmetic operators are listed in Table 3.2 below. Note the inclusion of
  1109. the integer division(%)and remainder(//)operators,along with the usual
  1110. arithmetic operations. The result of an arithmetic operation is always foratted
  1111. based on the current Numeric Digits setting,and will never have leading or
  1112. trailing blanks.
  1113.  
  1114.             TABLE 3.2 ARITHMETIC OPERATORS
  1115.     SEQUENCE        PRIORITY        OPERATION
  1116.     +            8            Prefix Conversion
  1117.     -            8            Prefix Negation
  1118.     **            7            Exponentiation
  1119.     *            6            Multiplication
  1120.     /            6            Division
  1121.     %            6            Integer Division
  1122.     //            6            Remainder
  1123.     +            5            Addition
  1124.     -            5            Subtraction
  1125.  
  1126. PREFIX CONVERSION(+). This unary operator converts the operand to and internal
  1127. numeric form and formats the result based on the current Numeric Digits
  1128. settings. This causes any leading and trailing blanks to be removed,and may
  1129. result in a loss of precision.
  1130. Examples:
  1131.  
  1132.     '  3.12 '        ==> 3.12
  1133.     1.5001            ==> 1.500 /* If digits = 3  */
  1134.  
  1135. PREFIX NEGATION(-). This unary operator negates the operand. The result is
  1136. formatted based on the current Numeric Digits setting.
  1137.  
  1138.                 18
  1139.  
  1140. Examples:
  1141.  
  1142.     -'  3.12 '        ==> -3.12
  1143.     1.5E2            ==>-150
  1144.  
  1145. EXPONENTIATION(**). The left operand is raised to the power specified by the
  1146. right operand,which must be an integer. The number of decimal places for the
  1147. result is the product of the exponent and the number of decimal places in the
  1148. base.
  1149. Examples:
  1150.  
  1151.     2**3            ==>8
  1152.     3**-1            ==>.333333333
  1153.     0.5**3            ==>0.125
  1154.  
  1155. MULTIPLICATION(*). The product of two numbers is computed. The number of
  1156. decimal places for the result is the sum of the decimal places of the operands.
  1157. Examples:
  1158.  
  1159.     12 * 3            ==>36
  1160.     1.5 * 1.50        ==>2.250
  1161.  
  1162. DIVISION(/). The quotient of two numbers is computed. The number of decimal
  1163. places for the result depends on the current setting of the numeric DIGITS
  1164. variable;the nuber is formatted to the maximum precision required.
  1165. Examples:
  1166.  
  1167.     6 / 3            ==>2
  1168.     8 / 3            ==>2.66666667
  1169.  
  1170. INTEGER DIVISION(%). The quotient of two numbers is computed,and the integer
  1171. part of the quotient is used as the result.
  1172. Examples:
  1173.  
  1174.     5 % 3            ==>1
  1175.     -8 % 3            ==>-2
  1176.  
  1177. REMAINDER(//). The result is the remainder after the two operands are divided.
  1178. The remainder for "a//b" is calculated as "a-(a%b)*b." If both operands are
  1179. positive integers,this operation yields the usual "modulo" result.
  1180.  
  1181.                 19
  1182.  
  1183. Examples:
  1184.  
  1185.     5 // 3            ==>2
  1186.     -5 // 3            ==>-2
  1187.     5.1 // 0.2        ==>0.1
  1188.  
  1189. ADDITION(+). The sum of two numbers is computed. The number of decimal places
  1190. for the result is the larger of the decimal places of the operands.
  1191. Examples:
  1192.  
  1193.     12 + 3            ==>15
  1194.     3.1 + 4.05        ==>7.15
  1195.  
  1196. SUBTRATION(-). The difference of two numbers is computed. As in the case of
  1197. addition,the number of decimals places for the result is the larger of the
  1198. decimal places of the operands.
  1199. Examples:
  1200.  
  1201.     12 - 3            ==>9
  1202.     5.55 - 1.55        ==>4.00
  1203.  
  1204. CONCATENATION OPERATORS
  1205.  
  1206. ARexx defines two concatenation operators,both of which require two operands.
  1207. The first,identified by the operator sequence "||",joins two strings into a
  1208. single string with no intervening blank. The second concatenation operation is
  1209. identified by the blank operator,and joins the two operand strings with one
  1210. intervening blank.
  1211.  
  1212. An implicit concatenation operator is recognized when a symbol and a string are
  1213. directly abutted in an expression. Concatenation by abuttal uses the "||"
  1214. operator,and behaves exactly as though the operator had been provided
  1215. explicitly.
  1216. Examples:
  1217.  
  1218.     'why me,' || 'Mom?'        ==>why me,Mom?
  1219.     'good' 'times'            ==>good times
  1220.     one'two'three            ==>ONEtwoTHREE
  1221.  
  1222. COMPARISON OPERATORS
  1223.  
  1224. Comparisons are performed in one of three modes,and always result in a boolean
  1225. value(0 or 1.)
  1226.  
  1227. Exact comparisons proceed character-by-character,including any leading blanks
  1228. that may be present.
  1229. String comparisons ignore leading blanks,and pad the shorter string with blanks
  1230. if necessary.
  1231.  
  1232.                 20
  1233.  
  1234. Numeric comparisons first convert the operands to an internal numeric form
  1235. using the current Numeric Digits setting,and then perform a standard arithmetic
  1236. comparison.
  1237.  
  1238. Except for the exact equality and exact inequality operators,all comparison
  1239. operators dynamically determine whether a string of numeric comparison is to be
  1240. performed. A numeric comparison is performed if both operands are valid numbers
  1241. otherwise,the operands are compared as strings.
  1242.  
  1243.             TABLE 3.3 COMPARISON OPERATORS
  1244.  
  1245. SEQUENCE    PRIORITY    OPERATION        MODE
  1246.  
  1247. ==        3        Exact Equality        Exact
  1248. ~==        3        Exact Inequality    Exact
  1249. =        3        Equality        String/Numeric
  1250. ~=        3        Inequality        String/Numeric
  1251. >        3        Greater Than        String/Numeric
  1252. >=,~<        3        Greater Than or Equal    String/Numeric
  1253. <        3        Less Than        String/Numeric
  1254. <=,~>        3        Less Than or Equal    String/Numeric
  1255.  
  1256. LOGICAL (BOOLEAN) OPERATORS
  1257.  
  1258. ARexx defines the four logical operations NOT,AND,OR,and Exclusive OR,all of
  1259. which require boolean operands and produce a boolean result. Boolean operands
  1260. must have values of either 0(False)or 1(True.) An attempt to perform a logical
  1261. operation on a non-boolean operand will generate an error.
  1262.  
  1263.             TABLE 3.4 LOGICAL OPERATORS
  1264.  
  1265.     SEQUENCE    PRIORITY    OPERATION
  1266.  
  1267.     ~        8        NOT(Inversion)
  1268.     &        2        AND
  1269.     |        1        OR
  1270.     ^,&&        1        Exclusive OR
  1271.  
  1272. 3-7 STEMS AND COMPOUND SYMBOLS
  1273.  
  1274. Stems and compound symbols have special properties that allow for some
  1275. interesting and unusual programming. A compound symbol can be regarded as
  1276. having the structure stem.n1.n2.n3...nk where the leading name is a stem symbol
  1277. and each node n1...nk is a fixed or simple symbol. Whenever a compound symbol
  1278. appears in a program,its name is expanded by replacing each node with its
  1279. current value as a (simple) symbol. The value string may consist of any
  1280. characters,including embedded blanks,and is not converted to uppercase. The
  1281. result of the expansion is a new name that is used in place of the compound
  1282. symbol. For example if j has the value of 3 and k has the value 7,then the
  1283. compound symbol a.j.k will expand to A.3.7.
  1284.  
  1285. Stem symbols provide a way to initialize a whole class of compound symbols.
  1286. When an assignment is made to a stem symbol,it assigns that value to all
  1287. possible compound symbols derived from the stem. Thus,the value of a compound
  1288. symbol depends on the prior assignments made to itself or its associated stem.
  1289.  
  1290.                 21
  1291.  
  1292. Compound symbols can be regarded as a form of "associative" or "content-
  1293. addressable" memory. For example,suppose that you needed to store and retrieve
  1294. a set of names and telephone numbers. The conventional approach would be to set
  1295. up two arrays NAME and NUMBER,each indexed by an integer running from one to
  1296. the number of entries. A number would be "looked up" by scanning the name array
  1297. until the given name was found,say in NAME.12,and then retrieving NUMBER.12.
  1298. With compound symbols,the symbol NAME could hold the name to be looked-up,and
  1299. NUMBER.NAME would then expand to NUMBER.Bill(for example),which be the
  1300. corresponding number.
  1301.  
  1302. Of course,compound symbols can also be used as conventional indexed arrays,with
  1303. the added convenience that only a single assignment(to the stem)is required to
  1304. initialize the entire array.
  1305.  
  1306. 3-8 THE EXECUTION ENVIRONMENT
  1307.  
  1308. The ARexx interpreter provides a uniform environment by running each program as
  1309. a separate task(actually,as a DOS process)in the Amiga's multitasking operating
  1310. system. This allows for a flexible interface between an external host program
  1311. and the interpreter,as the host can either proceed concurrently with its
  1312. operations or can simply wait for the interpreted program to finish.
  1313.  
  1314. THE EXTERNAL ENVIRONMENT
  1315.  
  1316. The external environment of a program includes its task(process)structure,
  1317. input and output streams,and current directory. When each ARexx task is
  1318. created,it inherits the input and output streams and current directory from its
  1319. client,the external program that invoked the ARexx program. The current
  1320. directory is used as the starting point in a search for a program or data file.
  1321.  
  1322. EXTERNAL PROGRAMS. The external environment usually includes one or more
  1323. external programs with which the ARexx program may communicate. Any program
  1324. that supports a suitable interface can receive commands from ARexx programs.
  1325. The command interface is discussed in Chapter 5.
  1326.  
  1327. THE INTERNAL ENVIRONMENT
  1328.  
  1329. The internal environment of an ARexx program consists of a static global
  1330. structure and one or more storage environments. The global data values are
  1331. fixed at a time the program is invoked,and include the argument strings,program
  1332. source code,and static data strings. The storage environment includes the
  1333. symbol table used for variable values,the numeric options,trace options,and
  1334. host address strings. While the global environment is unique,there may be many
  1335. storage environments during the course of the program execution. Each time an
  1336. internal function is called a new storage environment is activated and
  1337. initialized. The initial values for most fields are inherited from the previous
  1338. environment,but values may be changed afterwards without affecting the caller's
  1339. environment. The new environment persists until control returns from the
  1340. function.
  1341.  
  1342.                 22
  1343.  
  1344. ARGUMENT STRINGS. A program may receive one or more argument strings when it is
  1345. first invoked. These arguments persist for the duration of the program and are
  1346. never altered. The number of arguments a program receives depends in part on
  1347. the mode of invocation. ARexx programs invoked as commands normally have only
  1348. one argument string,although the "command tokenization" option may provide more
  1349. than one. A program invoked as a function can have any number of arguments if
  1350. called as an internal function,but external functions are limited to a maximum
  1351. of 15 arguments.
  1352.  
  1353. The argument strings can be retrieved using either the ARG instruction or the
  1354. ARG() Built-In function. ARG() can also return the total number of arguments,or
  1355. the status(as "exists" or "omitted")of a particular argument.
  1356.  
  1357. THE SYMBOL TABLE. Every storage environment includes a symbol table to store
  1358. the value strings that have been assigned to variables. This symbol table is
  1359. organized as a two-level stores entries for simple and stem symbols,and the
  1360. secondary level is used for compound symbols. All of the compound symbols
  1361. associated with a particular stem are stored in one tree,with the root of the
  1362. tree held by the entry for the stem.
  1363.  
  1364. Symbols are not entered into the table until an assignment is made to the
  1365. symbol. Once created,entries at the primary level are never removed,even if the
  1366. symbol subsequently becomes uninitialized. Secondary trees are released
  1367. whenever an assignment is made to the stem associated with the tree.
  1368.  
  1369. For the most part ARexx programmers need not be concerned with the details of
  1370. storage environments except to understand what values are saved when a function
  1371. is called. Applications developers who need to manipulate environment values
  1372. should refer to the structure definitions in the INCLUDE files provided on the
  1373. ARexx distribution disk.
  1374.  
  1375. INPUT AND OUTPUT
  1376.  
  1377. Most computer programs require some means of communicating with the outside
  1378. world,either to accept input data or to pass along results. The REXX language
  1379. includes only a minimal specification of input and output (I/O)operations,
  1380. leaving the choice of additional functionality to the language implementor.
  1381. This is in keeping with the design of many computer languages. For instance,the
  1382. "C" language has no statements dedicated to I/O,but instead relies on a
  1383. standardized set of I/O functions.
  1384.  
  1385. ARexx extends the I/O facilities fo REXX by providing Built-In functions to
  1386. manipulate external files. Files are referenced by a logical name associated
  1387. with the file when it is first opened. The initial input and output streams are
  1388. given the names STDIN and STDOUT.
  1389.  
  1390. ARexx maintains a list of all of the files opened by a program and
  1391. automatically closes them when the program finishes. There is no limit to the
  1392. number of files that may be open simultaneously.
  1393.  
  1394.                 23
  1395.  
  1396. RESOURCE TRACKING
  1397.  
  1398. ARexx provides complete tracking for all of the dynamically-allocated resources
  1399. that it uses to execute a program. These resources include memory space,DOS
  1400. files and related structures,and the message port structures supported by
  1401. ARexx. The tracking system was designed to allow a program to "bail out" at any
  1402. point(perhaps due to an execution error)without leaving any hanging resources.
  1403.  
  1404. It is possible to go outside of the interpreter's resource tracking net by
  1405. making calls directly to the Amiga's operating system from within an ARexx
  1406. program. In these cases it is the programer's responsibility to track and
  1407. return all of the allocated resources. ARexx provides a special interrupt
  1408. facility so that a program can retain control after an execution error,perform
  1409. the required cleanup,and then make an orderly exit. Chapter 7 has information
  1410. on the ARexx interrupt system.
  1411.  
  1412.                 24
  1413.  
  1414.             CHAPTER 4  INSTRUCTIONS
  1415.  
  1416. Instruction clauses are identified by an initial keyword symbol that is not
  1417. followed by a colon(:)or an equals(=)operator. Each instruction signifies a
  1418. specific action,and may be followed by one or more subkeywords,expressions,or
  1419. other instruction-specific information. Instruction keywords and subkeywords
  1420. are recognized only in this specific context,and are therefore not "reserved
  1421. words" in the usual sense of the term. Keywords may be used freely as variables
  1422. or function names,although such usage may become confusing at times.
  1423.  
  1424. In the descriptions that follow,keywords are shown in uppercase and optional
  1425. parts of the instruction are enclosed in brackets. Alternative selections are
  1426. separated by a vertical bar(|),and required alternative are enclosed in braces
  1427. ({}).
  1428.  
  1429. 4-1 ADDRESS
  1430.  
  1431. Usage: ADDRESS [Symbol|string|VALUE] [expression]]
  1432. This instruction specifies a host address for commands issued by the
  1433. interpreter. A host address is the name associated with an external program to
  1434. which commands can be sent;external hosts are described in Chapter 5. ARexx
  1435. maintains two host addresses:a "current" and a "previous"address is lost,and
  1436. the "current" and a "previous" value. Whenever a new host address is supplied,
  1437. the "previous" address is lost,and the "current" address becomes the "previous"
  1438. one. These host addresses are part of a program's storage environment and are
  1439. preserved across internal function calls. The current address can be retrieved
  1440. with the Built-In function ADDRESS(). There are four distinct forms for the
  1441. ADDRESS instruction:
  1442.  
  1443. ADDRESS {string | symbol} expression. The expression is evaluated and the
  1444. result is issued to the host specified by the string or symbol,which is taken
  1445. as a literal. No changes are made to the current or previous address strings.
  1446. This provides a convenient way to issue a single command to an external host
  1447. without disturbing the current host addresses. The return code from the command
  1448. is treated as it would be from a command clause.
  1449.  
  1450. ADDRESS {string | symbol}. The string or symbol,taken as a literal,specifies
  1451. the new host address. The current host address becomes the previous address.
  1452.  
  1453. ADDRESS [VALUE] expression. The result of the expression specifies the new host
  1454. address,and the current address becomes the previous address. The VALUE keyword
  1455. may be omitted if the first token of the expression is not a symbol or string.
  1456.  
  1457. ADDRESS. This form interchanges the current and previous hosts. Repeated
  1458. execution will therefore "toggle" between the two host addresses.
  1459.  
  1460.     Examples:
  1461.  
  1462. address edit        /* set an new host address       */
  1463. address edit 'top'    /* move to the top        */
  1464. address VALUE edit n    /* compute a new host address    */
  1465. address            /* swap current and previous    */
  1466.  
  1467.                 25
  1468.  
  1469. Usage: ARG [template] [,template...]
  1470. ARG is shorthand form for the PARSE UPPER ARG instruction. It retrieves one or
  1471. more of the argument strings available to the program,and assigns values to the
  1472. variables in the template. The number of argument strings available depends on
  1473. the whether the program was invoked as a command or a function. Command
  1474. invocations normally have only one argument string,but functions may have up to
  1475. 15. The argument strings are not altered by the ARG instruction.
  1476.  
  1477. The structure and processing of templates is described briefly with the PARSE
  1478. instruction,and in greater depth in Chapter 8.
  1479.     Example:
  1480.  
  1481. arg first,second /* fetch arguments */
  1482.  
  1483. 4-3 BREAK
  1484.  
  1485. Usuage: BREAK
  1486. The BREAK instruction is used to exit from the range of a DO instruction or
  1487. from within an INTERPRETed string,and is valid only in these contexts. If used
  1488. within a DO statement,BREAK exits from the innermost DO statement containing
  1489. the BREAK. This contrasts with the otherwise similar LEAVE instruction,which
  1490. exits only from an interative DO.
  1491.     Example:
  1492.  
  1493. do            /* begin block        */
  1494.   if i>3 then break    /* all done?        */
  1495.   a = a + 1
  1496.   y.a = name
  1497.   end            /* end block        */
  1498.  
  1499. 4-4 CALL
  1500.  
  1501. Usage: CALL {symbol | string} [expression] [,expression,...]
  1502. The CALL instruction is used to invoke an internal or external function. The
  1503. function name is specified by the symbol or string token,which is taken as a
  1504. literal. Any expressions that follow are evaluated and become the arguments to
  1505. the called function. The value returned by the function is assigned to the
  1506. special variable RESULT. It is not an error if a result string is not returned;
  1507. in this case the variable RESULT is DROPed(becomes uninitialized.)
  1508.  
  1509. The linkage to the function is established dynamically at the time of the call.
  1510. ARexx follows a specific search order in attempting to locate the called
  1511. function;this process is described in Chapter 6.
  1512.     Example:
  1513.  
  1514. call center name,length+4,'+'
  1515.  
  1516.                 26
  1517.  
  1518. Usage: DO [var=exp] [To exp] [BY exp]] [FOR exp] [FOREVER] [WHILE exp | UNTIL
  1519. exp]
  1520. The DO instruction begins a group of instructions to be executed as a block.
  1521. The range of the DO instruction includes all statements up to and including an
  1522. eventual END instruction. There are two basic forms of the instruction:
  1523.  
  1524. The DO keyword by itself defines a block of instructions to be executed once.
  1525.  
  1526. If any iteration specifiers follow the DO keyword,the block of instructions is
  1527. executed repeatedly until a termination condition occurs.
  1528.  
  1529. An interative DO instruction is sometimes called a "loop",since the interpreter
  1530. "loops back" to perform the instruction repeatedly. The various parts of the DO
  1531. instruction are described below.
  1532.  
  1533. Initializer expression. An initializer expression of the form "variable=
  1534. expression" defines the index variable of the loop. The expression is evaluated
  1535. when the DO range is first activated,and the result is assigned to the index
  1536. variable. On subsequent iterations an expression of the form "variable =
  1537. variable + increment" is evaluated,where the increment is the result of the BY
  1538. expression. If specified, the initializer expression must precede any of the
  1539. other subkeywords.
  1540.  
  1541. BY expression. The expression following a BY symbol defines the increment to be
  1542. added to the index variable in each subsequent iteration. The expression must
  1543. yield a numeric result,which may be positive or negative and need not be an
  1544. integer. The default increment is 1.
  1545.  
  1546. TO expression. The result of the TO expression specifies the upper(or lower)
  1547. limit for the index variable. At each iteration the index variable is compared
  1548. to the TO result. If the increment(BY result)is positive and the variable is
  1549. greater than the limit,the DO instruction terminates and control passes to the
  1550. statement following the END instruction. Similarly,the loop terminates if the
  1551. increment is negative and the index variable is less than the limit.
  1552.  
  1553. FOR expression. The FOR expression must yield a positive whole number when
  1554. evaluated,and specifies the maximum number of iterations to be performed. The
  1555. loop terminates when this limit is reached irrespective of the value of the
  1556. index variable.
  1557.  
  1558. FOREVER. The FOREVER keyword can be used if an iterative DO instruction is
  1559. required but no index variable is necessary. Presumably the loop will be
  1560. terminated by a LEAVE or BREAK instruction contained within the loop body.
  1561.  
  1562. WHILE expression. The WHILE expression is evaluated at the beginning of each
  1563. iteration and must result in a boolean value. The iteration proceeds if the
  1564. result is 1;otherwise,the loop terminates.
  1565.  
  1566.                 27
  1567.  
  1568. UNTIL expression. The UNTIL expression is evaluated at the end of each
  1569. iteration and must result in a boolean value. The instruction continues with
  1570. the next iteration if the result is 0,and terminates otherwise.
  1571.  
  1572. The initializer,BY,TO,and FOR expressions are evaluated only when the
  1573. instruction is first activated,so the increment and limits are fixed throughout
  1574. the execution. Note that a limit need not be supplied;for example,the
  1575. instruction "DO i=1" will simply count away forever. Note also that only one of
  1576. the WHILE or UNTIL keywords can be specified.
  1577. Example:
  1578.  
  1579. do i=1 to limit for 5 while time <50
  1580.    y.1=i*time
  1581.    end
  1582.  
  1583. 4-6 DROP
  1584.  
  1585. Usage: DROP variable [variable...]
  1586. The specified variable symbols are reset to their uninitialized state,in which
  1587. the value of the variable is the variable name itself. It is not an error to
  1588. DROP a variable that is already uninitialized. DROPping a stem symbol is
  1589. equivalent to DROPping the values of all possible compound symbols derived from
  1590. that stem.
  1591. Example:
  1592.  
  1593. a=123        /* assign a value    */
  1594. drop a b    /* drop some        */
  1595. say a b        /* ==>A B        */
  1596.  
  1597. 4-7 ECHO
  1598.  
  1599. Usage: ECHO [expression]
  1600. The ECHO instruction is a synonym for the SAY instruction. It displays the
  1601. expression result on the console.
  1602. Example:
  1603.  
  1604. echo  "You don't SAY!"
  1605.  
  1606. 4-8 ELSE
  1607.  
  1608. Usage: ELSE [;] [conditional statement]
  1609. The ELSE instruction provides the alternative conditional branch for an IF
  1610. statement. It is valid only within the range of an IF instruction,and must
  1611. follow the conditional statement of the THEN branch. If the THEN branch wasn't
  1612. executed,the statement following the ELSE clause is performed.
  1613.  
  1614. Binding. ELSE clauses always bind to the nearest(preceding)IF statement. It may
  1615. be necessary to provide "dummy" ELSE clauses for the inner IF ranges of a
  1616. compound IF statement in order to allow alternative branches for the outer IF
  1617. statements. In this case it is not sufficient to follow the else with a
  1618. semicolon or a null clause. Instead,the NOP(no-operation)instruction can be
  1619. used for this purpose.
  1620.  
  1621.                 28
  1622.  
  1623. Example:
  1624.  
  1625. if 1 > 2 then say 'really?'
  1626.          else say 'I thought so'
  1627.  
  1628. 4-9 END
  1629.  
  1630. Usage: END [variable]
  1631. The END instruction terminates the range of a DO or SELECT instruction. If the
  1632. optional variable symbol is supplied,it is compared to the index variable of
  1633. the DO statement(which must therefore be iterative). An error is generated if
  1634. the symbols do not match,so this provides a simple mechanism for matching the
  1635. DO and END statements.
  1636. Example:
  1637.  
  1638. do i=1 to 5        /* index variable is I    */
  1639.    say i        
  1640.    end i        /* end "I" loop        */
  1641.  
  1642. 4-10 EXIT
  1643.  
  1644. Usage: EXIT [expression]
  1645. The EXIT instruction terminates the execution of a program,and is valid
  1646. anywhere within a program. The evaluated expression is passed back to the
  1647. caller as the function or command result.
  1648.  
  1649. Results Processing. The processing of the EXIT result depends on whether a
  1650. result string was requested by the calling program,and whether the current
  1651. invocation resulted from a command or function call. If a result string was
  1652. requested,the expression result is copied to a block of allocated memory and a
  1653. pointer to the block is returned as the secondary result of the call.
  1654.  
  1655. If the caller did not request a result string,and the program was invoked as a
  1656. command,then an attempt is made to convert the expression result to an
  1657. integer. This value is then returned as the primary result,with 0 as the
  1658. secondary result. This allows the EXIT expression to be interpreted as a
  1659. "return code" by the caller. Refer to Chapter 10 for further information on
  1660. the data structures used to return the result string.
  1661. Examples:
  1662.  
  1663. exit            /* no result needed    */
  1664. exit 12            /* an error return?    */
  1665.  
  1666. 4-11 IF
  1667.  
  1668. Usage: IF expression [THEN] [;] [conditional statement]
  1669. The IF instruction is used in conjunction with THEN and ELSE instruction to
  1670. conditionally execute a statement. The result of the expression must be a
  1671. boolean value. If the result is 1 (True),the statement following the THEN
  1672. symbol is executed;otherwise,control passes to the next statement(which might
  1673. be an ELSE clause.) The THEN keyword need not immediately follow the IF
  1674. expression,but may appear as a separate clause. The instruction
  1675.  
  1676.                 29
  1677.  
  1678. is actually analyzed as "IF expression; THEN; statement;." In essence,the IF
  1679. statement begins a syntactic range and establishes the test condition that
  1680. determines whether subsequent THEN or ELSE clauses will be performed.
  1681.  
  1682. Any valid statement may follow the THEN symbol;in particular,a "DO; ... END;"
  1683. group allows a series of statements to be performed conditionally.
  1684. Examples:
  1685.  
  1686. if result < 0 then exit    /* all done?   */
  1687.  
  1688. 4-12 INTERPRET
  1689.  
  1690. Usage: INTERPRET expression
  1691. The expression is evaluated and the result is executed as one or more program
  1692. statements. The statements are considered as a group,as though surrounded by a
  1693. "DO; ...;END" combination. Any statements can be included in the INTERPRETed
  1694. source,including DO or SELECT instruction.
  1695.  
  1696. An INTERPRET instruction activates a control range when it is executed,which
  1697. serves as a "fence" for LEAVE and ITERATE instructions. These instructions can
  1698. therefore be used only with DO-loops defined within the INTERPRET. The BREAK
  1699. instuction can be used to terminate the processing of INTERPRETed statements.
  1700. While it is not an error to include label clauses within the interpreted
  1701. string,only those labels defined in the original source code are searched
  1702. during a transfer of control.
  1703.  
  1704. The INTERPRET instruction can be used to solve programming problems in
  1705. interesting and novel ways. Programs can be constructed dynamically and then
  1706. executed using this instruction,or program fragments may be passed as arguments
  1707. to functions,which then INTERPRET them.
  1708. Example:
  1709.  
  1710. inst = 'say'        /* an instruction    */
  1711. interpret inst hello    /* ..."say HELLO"    */
  1712.  
  1713. 4-13 ITERATE
  1714.  
  1715. Usage: ITERATE [variable]
  1716. The ITERATE instruction terminates the current iteration of a DO instruction
  1717. and begins the next iteration. Effectively,control passes to the END statement
  1718. and then(depending on the outcome of the UNTIL expression)back to the DO
  1719. statement. The instruction normally acts on the innermost iterative DO range
  1720. containing the instruction. An error results if the LEAVE instruction is not
  1721. contained within an iterative DO instruction.
  1722.  
  1723. The optional variable symbol specifies which DO range is to be exited,in the
  1724. event that several nested ranges exist. The variable is taken as a literal and
  1725. must match the index variable of a currently active DO instruction. An error
  1726. results if no such matching DO instruction is found.
  1727.  
  1728.                 30
  1729.  
  1730. Example:
  1731.  
  1732.     do i=1 to 3
  1733.        if i=j then iterate i
  1734.        end
  1735.  
  1736. 4-14 LEAVE
  1737.  
  1738. Usage:LEAVE [variable]
  1739. LEAVE forces an immediate exit from the iterative DO range containing the
  1740. instruction. An error results if the LEAVE instruction is not contained within
  1741. an iterative DO instruction.
  1742.  
  1743. The optional variable symbol specifies which DO range is to be exited,in the
  1744. event that several nested ranges exist. The variable is taken as a literal and
  1745. must match the index variable of a currently active DO instruction. An error
  1746. results if no such matching DO instruction is found.
  1747. Example:
  1748.  
  1749.     do i=1 to limit
  1750.        if i > 5 then leave    /* maximum iterations  */
  1751.        end
  1752.  
  1753. 4-15 NOP
  1754.  
  1755. Usage: NOP
  1756. The NOP or "no-operation" instruction does just that:nothing. It is provided to
  1757. control the binding of ELSE clauses in compound IF statements.
  1758. Example:
  1759.  
  1760.     if i=j then        /* first (outer) IF    */
  1761.        if j=k then a=o    /* inner IF        */
  1762.         else nop    /* binds to inner IF    */
  1763.        else a=a+1        /* binds to outer IF    */
  1764.  
  1765. 4-16 NUMERIC
  1766.  
  1767. Usage: NUMERIC {DIGITS | FUZZ} expression
  1768.    or: NUMERIC FORM {SCIENTIFIC | ENGINEERING}
  1769. This instruction sets options relating to the numeric precision and format. The
  1770. valid forms of the NUMERIC instruction are:
  1771.  
  1772. NUMERIC DIGITS expression. Specifies the number of digits of precision for
  1773. arithmetic calculations. The expression must evaluate to a positive whole
  1774. number.
  1775.  
  1776. NUMERIC FUZZ expression. Specifies the number of digits to be ignored in
  1777. numeric comparison operations. This must be a positive whole number that is
  1778. less than the current DIGITS setting.
  1779.  
  1780. NUMERIC FORM SCIENTIFIC. Specifies that numbers that require exponential
  1781. notation be expressed in SCIENTIFIC notation. The exponent is adjusted so that
  1782. the mantissa (for non-zero) numbers) is between 1 and 10. This is the default
  1783. format.
  1784.  
  1785.                 31
  1786.  
  1787. NUMERIC FORM ENGINEERING. Selects ENGINEERING format for numbers that require
  1788. exponential notation. ENGINEERING format normalizes a number so that its
  1789. exponent is a multiple of three and the mantissa(if not 0)is between 1 and
  1790. 1000.
  1791.  
  1792. The numberic options are preserved when an internal function is called.
  1793. Examples:
  1794.  
  1795.     numeric digits 12        /* precision        */
  1796.     numeric form scientific        /* format        */
  1797.  
  1798. 4-17 OPTIONS
  1799.  
  1800. Usage: OPTIONS [FAILAT expression]
  1801.    or: OPTIONS [PROMPT expression]
  1802.    or: OPTIONS [RESULTS]
  1803. The OPTIONS instruction is used to set various internal defaults. The FAILAT
  1804. expression sets the limit at or above which command return codes will be
  1805. signalled as errors,and must evaluate to an integer value. The PROMPT
  1806. expression provides a string to be used as the prompt with the PULL (or PARSE
  1807. PULL)instruction. The RESULTS keyword indicates that the interpreter should
  1808. request a result string when it issues commands to an external host.
  1809.  
  1810. The internal options controlled by this instruction are preserved across
  1811. function calls,so an OPTIONS instruction can be issued within an internal
  1812. function without affecting the callers environment. If no keyword is specified
  1813. with the OPTIONS instuction,all controlled options revert to their default
  1814. settings.
  1815. Example:
  1816.  
  1817.     options failat 10
  1818.     options prompt "Yes Boss?"
  1819.     options results
  1820.  
  1821. 4-18 OTHERWISE
  1822.  
  1823. Usage: OTHERWISE [;] [conditional statement]
  1824. This instruction is valid only within the range of a SELECT instruction,and
  1825. must follow the "WHEN ... THEN" statements. If none of the preceding WHEN
  1826. clauses have succeeded,the statement following the OTHERWISE instruction is
  1827. executed. An OTHERWISE is not mandatory within a SELECT range. However,an error
  1828. will result if the OTHERWISE clause is omitted and none of the WHEN
  1829. instructions succeed.
  1830. Example:
  1831.  
  1832.     select
  1833.         when i=1 then say 'one'
  1834.         when i=2 then say 'two'
  1835.         otherwise say 'other'
  1836.         end
  1837.  
  1838.                 32
  1839.  
  1840. 4-19 PARSE
  1841.  
  1842. Usage: PARSE [UPPER] inputsorce [template] [,template...]
  1843. The PARSE instruction provides a mechanism to extract one or more substrings
  1844. from a string and assign them to variables. The input string can come from a
  1845. variety of sources,including argument strings,an expression,or from the
  1846. console. The template provides both the variables to be given values and the
  1847. way to determine the value strings. The template may be omitted if the
  1848. instruction is intended only to create the input string. The different options
  1849. of the instruction are described below.
  1850.  
  1851. INPUT SOURCES
  1852.  
  1853. The sources for the input strings are specified by the keyword symbols listed
  1854. below. When multiple templates are supplied,each template receives a new input
  1855. string, although for some source options the new string will be identical to
  1856. the previous one. The input source string is copied before being parsed,so the
  1857. original strings are never altered by the parsing process.
  1858.  
  1859. UPPER. This optional keyword may be used with any of the input sources,and
  1860. specifies that the input string is to be translated to uppercase before being
  1861. parsed. It must be the first token following PARSE.
  1862.  
  1863. ARG. This input option retrieves the argument strings supplied when the program
  1864. was invoked. Command invocations normally have only a single argument string,
  1865. but functions may have up to 15 argument strings. Multiple templates may be
  1866. given to retrieve successive argument strings.
  1867.  
  1868. EXTERNAL. The input strings is read from the console. If multiple templates are
  1869. supplied,each template will read a new string. This source option is the same
  1870. as PULL.
  1871.  
  1872. NUMERIC. The current numeric options are placed in a string in the order
  1873. DIGITS,FUZZ,and FORM,separated by a single space.
  1874.  
  1875. PULL. Reads a string from the input console. If multiple templates are
  1876. supplied,each template will read a new string.
  1877.  
  1878. SOURCE. The "source" string for the program is retrieved. This string is
  1879. formatted as "{COMMAND | FUNCTION} {0 | 1} called resolved ext host." The first
  1880. token indicates whether the program was invoked as a command or as a function.
  1881. The second token is a boolean flag indicating whether a result string was
  1882. requested by the caller. The called token is the name used to invoke this
  1883. program,while the resolved token is the final resolved name of the program. The
  1884. ext token is the file extension to be used for searching(the default is
  1885. "REXX"). Finally,the host token is the initial host address for commands.
  1886.  
  1887. VALUE expression WITH. The input string is the result of the supplied
  1888. expression. The WITH keyword is required to separate the expression from the
  1889. template. The expression result may be parsed repeatedly by using multiple
  1890. templates,but the expression is not reevaluated.
  1891.  
  1892. VAR variable. The value of the specified variable is used as the input string.
  1893. When multiple templates are provided,each template uses the current value of
  1894. the variable.
  1895.  
  1896.                 33
  1897.  
  1898. This value may change if the variable is included as an assignment target in
  1899. any of the templates.
  1900.  
  1901. VERSION. The current configuation of the ARexx interpreter is supplied in the
  1902. form "ARexx version cpu mpu video freq". The version toekn is the release level
  1903. of the interpreter,formatted as V1.0. The cpu token indicates the processor
  1904. currently running the program,and will be one of the values 68000,68010,or
  1905. 68020. The mpu token will be either NONE or 68881 depending on whether a math
  1906. coprocessor is available on the system. The video token will indicate either
  1907. NTSC or PAL,and the freq token gives the clock(line)frequency as either 60HZ or
  1908. 50 HZ.
  1909.  
  1910. TEMPLATES
  1911.  
  1912. Parsing is controlled by a template,which may consist of symbols,strings,
  1913. operators,and parentheses. During the parsing operation the input string is
  1914. split into substrings that are assigned to the variable symbols in the
  1915. template. The process continues until all of the variables in the template have
  1916. been assigned a value;if the input string is "used up",any remaining variables
  1917. are given null values.
  1918.  
  1919. Templates are described in depth in Chapter 8,so only a simplified description
  1920. is presented here. The goal of the parsing operation is to associate a
  1921. "current" and "next" position with each variable symbol in the template. The
  1922. substring between these positions is then assigned as the value to the
  1923. variable. There are three basic methods used to determine the value strings.
  1924.  
  1925. PARSING BY TOKENIZATION. When a variable in the template is followed
  1926. immediately by another variable,the value string is determined by breaking the
  1927. input string into words separated by blanks. Each word is assigned to a
  1928. variable in the template.
  1929.  
  1930. Values determined by tokenization will never have leading or trailing blanks.
  1931. Normally the last variable in the template receives the untokenized remainder
  1932. of the input string,since it is not followed by a symbol. A "placeholder"
  1933. symbol,signified by a period(.),may be used to force tokenization. Placeholders
  1934. behave like variables in the template except that they are never actually
  1935. assigned a value.
  1936. Example:
  1937.  
  1938.     /* Numeric string is: "9 0 SCIENTIFIC"    */
  1939.     parse numberic digits fuzz form .
  1940.     say digits        /* =>9            */
  1941.     say fuzz        /* =>0            */
  1942.     say from        /*=> SCEIENTIFIC    */
  1943.  
  1944. PARSING BY POSITION. If the fields in the input string have known positions,
  1945. value strings can be specified by absolute or relative positions. Relative
  1946. positions are indicated by a number preceded by a "+" or "-" operator. Each
  1947. positional marker updates the scan position in the string. The value assigned
  1948. to a variable is the string from the current position up to,but not including,
  1949. the next position in the string.
  1950.  
  1951.                 34
  1952.  
  1953. Example:
  1954.  
  1955.     /* assume argument is "1234567890"        */
  1956.     parse arg 1 a 3 b +2 1 c
  1957.     say a b c         /* ==> 12 34 1234567890    */
  1958.  
  1959. PARSING WITH PATTERNS. Fields in the input string separated by specific
  1960. characters or strings can be parsed using a pattern,which is matched against
  1961. the input string. A pattern is specified in the template as a string token,or
  1962. alternatively as a symbol enclosed in parentheses. The position in the parse
  1963. string matched by the pattern determines the value strings. The pattern is
  1964. removed from the input string when a match is found;this is the only parsing
  1965. operation that modifies the input string.
  1966. Example:
  1967.  
  1968.     check = 'one,two,three'
  1969.     parse var check a ',' b ',' c
  1970.     say a b c    /* ==> one two three    */
  1971.  
  1972. 4-20 PROCEDURE
  1973.  
  1974. Usage:PROCEDURE [EXPOSE variable [variable...]]
  1975. The PROCEDURE instruction is used within an internal function to create a new
  1976. symbol table. This protects the symbols defined in the caller's environment
  1977. from being altered by the execution of the function. PROCEDURE is usually the
  1978. first statement within the function,although it is valid anywhere withing the
  1979. function body. It is an error to execute two PROCEDURE statements within the
  1980. function.
  1981.  
  1982. EXPOSING VARIABLES. The EXPOSE subkeyword provides a selective mechanism for
  1983. accessing the caller's symbol table,and for passing global variables to a
  1984. function. The variables following the EXPOSE keyword are taken to refer to
  1985. symbols in the caller's table. Any subsequent changes made to these variables
  1986. will be reflected in the caller's environment.
  1987.  
  1988. The variables in the EXPOSE list may include stems or compound symbols,in which
  1989. case the ordering of the variables becomes significant. The EXPOSE list is
  1990. processed from left to right,and compound symbols are expanded based on the
  1991. values in effect in the new generation. For example,suppose that the value of
  1992. the symbol J in the previous gneration is 123,and that J is unitialized in the
  1993. new generation. Then PROCEDURE EXPOSE J A.J will expose J and A.123,whereas
  1994. PROCEDURE EXPOSE A.J J will expose A. J. and J. Exposing a stem has the effect
  1995. of exposing all possible compound symbols derived from that stem.
  1996. Example:
  1997.  
  1998.     fact: procedure        /* a recursive function    */
  1999.        arg i
  2000.        if i <=1
  2001.           then return 1
  2002.           else return i*fact(i-1)
  2003.  
  2004.                 35
  2005.  
  2006. Usage:PULL [template] [,template...]
  2007. This is a shorthand form of the PARSE UPPER PULL instruction. It reads a string
  2008. from the input console,translates it to uppercase,and parses it using the
  2009. template. Multiple strings can be ready by supplying additional templates. The
  2010. instruction will read from the console even if no template is given.
  2011.  
  2012. Templates are described briefly with the PARSE instruction and in greater depth
  2013. in Chapter 8.
  2014. Example:
  2015.  
  2016.     pull first last.    /* read names        */
  2017.  
  2018. 4-22 PUSH
  2019.  
  2020. Usage: PUSH [expression]
  2021. The PUSH instruction is used to prepare a stream of data to be ready by a
  2022. command shell or other program. It appends a "newline" to the result of the
  2023. expression and then stacks or "pushes" it into the STDIN stream. Stacked lines
  2024. are placed in the stream in "last-in, first-out" order,and are then available
  2025. to be ready just as though they had been entered interactively. For example,
  2026. after issuing the instructions
  2027.  
  2028.     push line 1
  2029.     push line 2
  2030.     push line 3
  2031.  
  2032. the steam would be read in the order "line 3," "line 2" and "line 1."
  2033.  
  2034. There are several restrictions governing the use of the PUSH instruction and
  2035. its alter ego QUEUE. These instructions use a special I/O mechanism to
  2036. accomplish their task,and as a result can be used only with an interactive
  2037. (stream-model) I/O device like a console or pipe. The stream must be managed by
  2038. with a DOS handler that supports the special ACTION_STACK (for PUSH) or
  2039. ACTION_QUEUE (for QUEUE) command.
  2040.  
  2041. PUSH allows the STDIN stream to be used as a private scratchpad to prepare data
  2042. for subsequent processing. For example,several files could be concatenated with
  2043. delimiters between them by simply reading the input files,PUSHing the lines
  2044. into the stream,and inserting a delimiter where required. Once the stacked
  2045. lines are exhausted,the stream reverts to its normal source of data.
  2046. Example:
  2047.  
  2048.     /* Stack commands for compile and link*/
  2049.     push "blink c.o+main.o library amiga.lib to myprog"
  2050.     push "cc main"
  2051.  
  2052.                 36
  2053.  
  2054. 4-23 QUEUE
  2055.  
  2056. Usage:QUEUE [expression]
  2057. The QUEUE instruction is used to prepare a stream of data to be read by a
  2058. command shell or other program. It is very similar to the preceding PUSH
  2059. instruction,and differs only that the data lines are placed in the STDIN stream
  2060. in "first-in,first-out" order. In this case the instruction
  2061.  
  2062.     queue line 1
  2063.     queue line 2
  2064.     queue line 3
  2065.  
  2066. would be read in the order "line 1," "line 2," and "line 3." The QUEUEd lines
  2067. always precede all interactivly-entered lines,and always follow any PUSHed
  2068. (stacked)lines.
  2069.  
  2070. The same restriction noted with the use of the PUSH instruction apply to the
  2071. QUEUE instruction. The queueing mechanism uses the ACTION_QUEUE command,so the
  2072. DOS handler associated with the STDIN stream must support this command.
  2073.  
  2074. In most cases the choice of whether to use PUSH or QUEUE is just a matter of
  2075. convenience or personal preference. Each of them provides a "scratch pad"
  2076. facility similar to that provided by an I/O pipe,but useful within one program
  2077. or task rather than just for interprocess communications.
  2078. Example:
  2079.  
  2080.     /* Queue commands for compile and link */
  2081.     queue "cc main"
  2082.     queue "blink c.o+main.o library amiga.lib to myprog"
  2083.  
  2084. 4-24 RETURN
  2085. RETURN is used to leave a function and return control to the point of the
  2086. previous function invocation. The evaluated expression is returned as the
  2087. function result. If an expression is not supplied,an error may result in the
  2088. caller's environment. Functions called from within an expression must return a
  2089. result string,and will generate an error if no result is available. Function
  2090. invoked by the CALL instruction need not return a result.
  2091.  
  2092. A RETURN issued from the base environment of a program is not an error,and is
  2093. equivalent to an EXIT instruction. Refer to the EXIT instruction for a
  2094. description of how result strings are passed back to an external caller.
  2095. Example:
  2096.  
  2097.     return 6*7        /*the answer    */
  2098.  
  2099.                 37
  2100.  
  2101. 4-25 SAY
  2102.  
  2103. Usage:SAY [expression]
  2104. The result of the evaluated expression is written to the output console,with a
  2105. "newline" character appended. If the expression is omitted,a null string is
  2106. sent to the console.
  2107. Example:
  2108.  
  2109.     say 'The anwer is ' value
  2110.  
  2111. 4-26 SELECT
  2112.  
  2113. Usage:SELECT
  2114. This instruction begins a group of instructions containing one or more WHEN
  2115. clauses and possibly a single OTHERWISE clause,each followed by a conditional
  2116. statement.
  2117.  
  2118. Only one of the conditional statements within the SELECT group will be
  2119. executed. Each WHEN statement is executed in succession until one succeeds;if
  2120. none succeeds,the OTHERWISE statement is executed. The SELECT range must be
  2121. terminated by an eventual END statement.
  2122. Example:
  2123.  
  2124.     select
  2125.         when i=1 then say 'one'
  2126.         when i=2 then say 'two'
  2127.         otherwise say 'other'
  2128.         end
  2129.  
  2130. 4-27 SHELL
  2131.  
  2132. Usage:SHELL [symbol | string] [expression]
  2133. The SHELL instruction is a synonym for the ADDRESS instruction.
  2134. Example:
  2135.  
  2136.     shell edit    /* set host to 'EDIT'    */
  2137.  
  2138. 4-28 SIGNAL
  2139.  
  2140. Usage: SIGNAL {ON |OFF} condition
  2141.    or: SIGNAL [VALUE] expression
  2142. There are two forms of the SIGNAL instruction. The first form illustrated
  2143. controls the state of the internal interrupt flags. Interrupts allow a program
  2144. to detect and retain control when certain errors occur,and are discussed in
  2145. Chapter 7. In this form SIGNAL must be followed by one of the keywords ON or
  2146. OFF and one of the condition keywords listed below. The interrupt flag
  2147. specified by the condition symbol is then set to the indicated state. The valid
  2148. signal conditions are:
  2149.  
  2150. BREAK_C  A "control-C" break was detected.
  2151. BREAK_D  A "control-D" break was detected.
  2152. BREAK_E  A "control-E" break was detected.
  2153.  
  2154.                 38
  2155.  
  2156. BREAK_F A "control-F" break was detected.
  2157. ERROR A Host command returned a non-zero code.
  2158. HALT  An external HALT request was detected.
  2159. IOERR An error was detected by the I/O system.
  2160. NOVALUE An uninitialized variable was used.
  2161. SYNTAX  A syntax or execution error was detected.
  2162.  
  2163. The condition keywords are interpreted as labels to which control will
  2164. transferred if the selected condition occurs. For example,if the ERROR
  2165. interrupt is enabled and a command returns a non-zero code,the interpreter will
  2166. transfer control to the label ERROR:. The condition label must of course be
  2167. defined in the program;otherwise,an immediate SYNTAX error results and the
  2168. program exits.
  2169.  
  2170. In the second form of the instruction,the tokens following SIGNAL are evaluated
  2171. as an expression. An immediate interrupt is generated that transfers control to
  2172. the label specified by the expression result. The instruction thus acts as a
  2173. "computed goto."
  2174.  
  2175. INTERRUPTS. Whenever an interrupt occurs,all currently active control ranges
  2176. (IF,DO,SELECT,INTERPRET,or interactive TRACE) are dismantled before the
  2177. transfer of control. Thus,the transfer cannot be used to jump into the range of
  2178. a DO-loop or other control structure. Only the control structures in the
  2179. current environment are affected by a SIGNAL condition,so it is safe to SIGNAL
  2180. from within an internal function without affecting the state of the caller's
  2181. environment.
  2182.  
  2183. SPECIAL VARIABLES. The special variable SIGL is set to the current line number
  2184. whenever a transfer of control occurs. The program can inspect SIGL to
  2185. determine which line was being executed before the transfer. If an ERROR or
  2186. SYNTAX condition causes an interrupt,the special variable RC is set to the
  2187. error code that triggered the interrupt. For the ERROR condition,this code is
  2188. usually an error secerity level. The SYNTAX condition will always indicate an
  2189. ARexx error code.
  2190. Examples:
  2191.  
  2192.     signal on error        /* enable interrupt    */
  2193.     signal off syntax    /* disable SYNTAX    */
  2194.     signal start        /* goto START        */
  2195.  
  2196. 4-29 THEN
  2197.  
  2198. Usage:THEN[;] [conditional statement]
  2199. The THEN instruction must be the next statement following an IF or WHEN
  2200. instruction,and is valid only in that context. It tests whether the preceding
  2201. expression evaluated to 1(True),in which case the conditional statement
  2202. following the THEN is performed. If the expression result was a 0(False),the
  2203. conditional statement is skipped.
  2204.  
  2205.                 39
  2206.  
  2207. Example:
  2208.  
  2209.     if i=j
  2210.        then say 'equal'
  2211.        else say 'not equal'
  2212.  
  2213. 4-30 TRACE
  2214.  
  2215. Usage:TRACE [symbol|string|[[VALUE] expression]]
  2216. The TRACE instruction is used to set the internal tracing mode. If a symbol or
  2217. string is supplied,it is taken as a literal. Otherwise,the tokens following the
  2218. VALUE keyword are evaluated as an expression. The VALUE keyword can be omitted
  2219. if the expression doesn't start with a symbol or string token.
  2220.  
  2221. In either case the result string is converted to uppercase and checked first
  2222. for one of the "alphabetic" options. The valid alphabetic options are ALL,
  2223. COMMANDS,ERRORS,INTERMEDIATES,LABELS,RESULTS,and SCAN. These can be spelled out
  2224. in full or shortened to the initial character,and are described in Chapter 7.
  2225. If the result doesn't match any of these options,the interpreter attempts to
  2226. convert it to an integer. A conversion failure here will be reported as an
  2227. error.
  2228.  
  2229. PREFIX CHARACTERS. Two special symbol characters may precede any of the
  2230. alphabetic keywords. The "?" character interactive tracing,and the "!"
  2231. character controls command inhibition. These characters act as "toggles" to
  2232. alternatively select and de-select the respective modes. Any number of prefix
  2233. characters may precede an alphabetic option. Interactive tracing and command
  2234. inhibition are described in Chapter 7.
  2235.  
  2236. NUMERIC OPTION. If the specified trace option is a negative whole number,it is
  2237. accepted as a trace suppression count. The suppression count is the number of
  2238. clauses(that would otherwise be traced)to be passed over before resuming the
  2239. tracing display. Suppression counts are ignored execept during interactive
  2240. tracing.
  2241. Examples:
  2242.  
  2243.     trace ?r        /* interactive RESULTS    */
  2244.     trace off
  2245.     trace -20        /* skip 20 clauses    */
  2246.  
  2247. 4-31 UPPER
  2248.  
  2249. Usage:UPPER variable [variable...]
  2250. The values of the variables in the list are converted to uppercase. It is not
  2251. an error to include an uninitialized variable in the list,but it will be
  2252. trapped if the NOVALUE interrupt has been enabled.
  2253.  
  2254. The TRANSLATE() or UPPER() Built-In functions could also be used to convert
  2255. variables to uppercase,but the instruction form is more concise(and faster) if
  2256. several variables are being converted.
  2257.  
  2258.                 40
  2259.  
  2260. Example:
  2261.  
  2262.     when='Now is the time'
  2263.     upper when
  2264.     say when        /* NOW IS THE TIME    */
  2265.  
  2266. 4-32 WHEN
  2267.  
  2268. Usage:WHEN expression [THEN [;] [conditional statement]]
  2269. The WHEN instruction is similar to the IF instruction,but is valid only within
  2270. a SELECT range. Each WHEN expression is evaluated in turn and must result in a
  2271. boolean value. If the result is a 1,the conditional statement is executed and
  2272. control passes to the END statement that terminates the SELECT. As in the case
  2273. of the IF instruction,the THEN need not be part of the same clause.
  2274. Example:
  2275.  
  2276.     select;
  2277.        when i<j thn say 'less'
  2278.        when i=j then say 'equal'
  2279.        otherwise     say 'greater'
  2280.        end
  2281.  
  2282.                 41
  2283.  
  2284.                           CHAPTER 5  COMMANDS
  2285.  
  2286. The REXX language is unusual in that an entire syntactic class of program
  2287. statements are reserved for cmmands,statements that have meaning not within the
  2288. language itself but rather to an external program. When a command clause is
  2289. found in a program,it is evaluated as an expression and then sent through the
  2290. command interface to an explicit or implicit host application,an external
  2291. program that has announced its ability to receive commands. The host
  2292. application then processes the command and returns a result code that indicates
  2293. whether the command was performed successfully. In this manner every host
  2294. program becomes fully programmable,and with even a limited set of predefined
  2295. operations can be customized by the end user.
  2296.  
  2297. This chapter discusses the ARexx command interface and examines some of the
  2298. ways in which commands can be used to build programs for an external program.
  2299. Such programs are ofter called "macro programs" because they implement a
  2300. complex ("macro") action from a series of simpler "micro" commands.
  2301.  
  2302. Chapter 10 has detailed information on the data structers required to implement
  2303. a command interface for an applications program.
  2304.  
  2305. 5-1 COMMAND CLAUSES
  2306.  
  2307. Syntactically,a command clause is just an expression that can't be classified
  2308. as another type of clause. The actual structure of the command is dictated by
  2309. the external host to which it is intended,but in most cases will follow the
  2310. model of a name or letter followed by parameter data. Command names can be
  2311. given as either a symbol or a string. However,it is generally safer to use a
  2312. string for the name,since it can't be assigned a value or be mistaken for an
  2313. instruction keyword. For example,the following might be commands for a text
  2314. editor:
  2315.  
  2316.     JUMP current+10        /* advance to next    */
  2317.     'insert' newstring    /* blast it in        */
  2318.     'TOP'            /* back to the top    */
  2319.  
  2320. Since command clauses are expressions,they are fully evaluated before being
  2321. sent to the host. Any part of the final command string can be computed within
  2322. the program,so virtually any sort of command structure can be created.
  2323.  
  2324. The interpretation of the received commands depends entirely on the host
  2325. application. In the simplest case the command strings will correspond exactly
  2326. to commands that could be entered directly by a user. For instance,positional
  2327. control(up/down)commands for a text editor would probably have identical
  2328. interpretations whether issued by the user or from a program. Other commands
  2329. may be valid only when issued from a macro program;a command to simulate a menu
  2330. operation would probably not be entered by the user.
  2331.  
  2332.                 43
  2333.  
  2334. 5-2 THE HOST ADDRESS
  2335.  
  2336. The destination for a command is determined by the current host address,which
  2337. is the name of the public message port managed by an external program. ARexx
  2338. maintains two implicit host addresses,a "current" and a "previous" value,as
  2339. part of the program's storage environment. These values can be changed at any
  2340. time using the ADDRESS instruction(or its synonym,SHELL,)and the current host
  2341. address can be inspected with the ADDRESS()Built-In fuction. The default host
  2342. address string is "REXX",but this can be overridden when a program is invoked.
  2343. In particular,most host applications will supply the name of their public port
  2344. when they invoke a macro program,so that the macro can automatically issue
  2345. commands back to the host.
  2346.  
  2347. One special host address is recognized: the string COMMAND indicates that the
  2348. command should be issued directly to the underlying DOS. All other host
  2349. addresses are assumed to refer to a public message port. An attempt to send a
  2350. commmand to a non-existent message port will generate the syntax error "Host
  2351. environment not found."
  2352.  
  2353. Single commands can be sent to a specific host without disturbing the host
  2354. address settings. This is done using the ADDRESS instruction,as the following
  2355. example illustrates:
  2356.  
  2357. ADDRESS MYEDIT 'jump top'
  2358.  
  2359. This example would send the command "jump top" to an external host named
  2360. "MYEDIT."
  2361.  
  2362. It is important to note that you cannot send commands to a host application
  2363. without knowing the name of its public message port. Writing macro programs to
  2364. communicate with two or more hosts may require some clever programming to
  2365. determine whether both hosts are active and what their respective host
  2366. addresses are.
  2367.  
  2368. 5-3 THE COMMAND INTERFACE
  2369.  
  2370. ARexx implements its command interface using the message-passing facilities
  2371. provided by the EXEC operating system. Each host application must provide a
  2372. public message port,the name of which is referred to as the host address. ARexx
  2373. programs issue commands by placing the command string in a message packet and
  2374. sending the packet to the host's message port. The program "sleeps" while the
  2375. host processes the command,and awakens when the message packet returns. The
  2376. entire process can be regarded as a dialogue between the host application and a
  2377. macro program:the host initiates the dialogue by invoking the macro,and the
  2378. macro program replies with one or more command strings. The commands that can
  2379. be sent are not limited to simple text strings,but might be address pointers or
  2380. even bit-mapped images.
  2381.  
  2382. After it finishes processing a command,the host "replies" the message packet
  2383. with a return code that indicates the status of the command. This return code
  2384. is placed in the ARexx special variable RC so that it can be examined by the
  2385. program. A value of zero is assumed to mean that no errors occurred,while
  2386. positive values usually indicate progressively more severe error conditions.
  2387. The return code allows the macro program to determine whether the command
  2388. succeeded and to take action if it failed,so it is important for each
  2389. applictions program to document the meanings of the return codes for its
  2390. commands.
  2391.  
  2392.                 44
  2393.  
  2394. 5-4 USING COMMANDS IN MACRO PROGRAMS
  2395.  
  2396. ARexx can be used to write programs for any host application that includes a
  2397. suitable command interface. Some applications programs are designed with an
  2398. embedded macro language,and may include many predefined macro commands. With a
  2399. well-designed macro language interface the user will be usually unaware of
  2400. whether a given action is implemented as a primitive operations or as a macro
  2401. program.
  2402.  
  2403. The starting point in designing a macro program is to examine the commands that
  2404. would be required to perform it manually. The documentation for the host
  2405. application program should then describe the possible return codes for each
  2406. command;these codes can be used to determine whether the operation performed by
  2407. the command was successful. Check also for "shortcut" commands that may be
  2408. available only to macro programs;some applications programs may include very
  2409. powerful functions that were implemented specifically for use in macro
  2410. programs.
  2411.  
  2412. 5-5 USING AREXX WITH COMMAND SHELLS
  2413.  
  2414. Although ARexx was designed to work most effectively with programs that support
  2415. its specific command interface,it can be used with any "command shell" program
  2416. that uses standards I/O mechanisms to obtain its input stream. There are
  2417. several ways to use ARexx to prepare a stream of commands for such program.
  2418.  
  2419. One obvious technique is to create an actual command file on the "RAM:" disk
  2420. and then pass it directly to the command shell. For example,you could open a
  2421. new CLI window to run a standard "execute" script using the following short
  2422. program:
  2423.  
  2424.     /* Launch a new CLI    */
  2425.     address command
  2426.     conwindow = "CON:0/0/640/100/NewOne"
  2427.  
  2428.     /* create a command file on the fly  */
  2429.     call open out,"ram:$$temp",write
  2430.     call writeln out,'echo "this is a test"'
  2431.     call close out
  2432.  
  2433.     /* open the new CLI window */
  2434.     'newcli' conwindow "ram:$$temp"'
  2435.     exit
  2436.  
  2437. Since no disk accesses are required,this method is actually fairly fast,if not
  2438. very elegant.
  2439.  
  2440. Another alternative is to use the command stacking facility provided by the
  2441. PUSH and QUEUE instructions. These instructions allow an ARexx program to stack
  2442. an arbitrary stream of commands and data for the command shell or other program
  2443. to read. Any set of commands that could be "typed ahead" at a command prompt
  2444. can be prepared in this fashion. After the ARexx program exits,the next program
  2445. that uses the input stream will read the prepared commands and can process them
  2446. in the normal fashion.
  2447.  
  2448.                 45
  2449.  
  2450. 5-6 COMMAND INHIBITION
  2451.  
  2452. Sometimes it is necessary to write and test macro programs that issue
  2453. potentially destructive commands. For instance,a program to find and delete
  2454. unneeded files would be difficult to test safely,since it might accidentally
  2455. delete the wrong files and would require a continual source of new files for
  2456. testing.
  2457.  
  2458. To simply the development and testing of such programs,ARexx provides a special
  2459. tracing mode called command inhibition that suppresses host commands. While in
  2460. command inhibition mode,command processing proceeds normally except that the
  2461. command is not actually issued and the variable RC is set to 0. This allows the
  2462. program logic to be verified before any commands are actually sent to the
  2463. external program. Chapter 7 has further information on this facility.
  2464.  
  2465.                 46
  2466.  
  2467.                            CHAPTER 6  FUNCTIONS
  2468.  
  2469. The basic concept of a function is a program or group of statements that will
  2470. be executed whenever the function name appears in a certain context. Functions
  2471. are an important building block of most computer languages in that they allow
  2472. modular programming -- the ability to build a large program from a series of
  2473. smaller,more easily developed modules. In ARexx a function may be defined as
  2474. part of(internal to)a program,as part of a library,or as a separate external
  2475. program.
  2476.  
  2477. 6-1 SYNTAX AND SEARCH ORDER
  2478.  
  2479. Function calls in an expression are defined syntactically as a symbol or string
  2480. followed immediately by an open parenthesis. The symbol or string(taken an a
  2481. literal)specifies the function name,and the open parenthesis begins the
  2482. argument list. Between the opening and eventual closing parentheses are zero or
  2483. more argument expressions,separated by commas,that supply the data being passed
  2484. to the function. For example,
  2485.  
  2486.     CENTER('title",20)
  2487.     ADDRESS()
  2488.     'AllocMem'(256*4,1)
  2489.  
  2490. are all valid function calls. Each argument expression is evaluated in turn and
  2491. the resulting strings are passed as the argument list to the function. There is
  2492. no limit to the number of arguments that may be passed to an internal
  2493. function,but calls to Built-In or external functions are limited to a maximum
  2494. of 15 arguments. Note that each argument expression,while ofter just a single
  2495. literal value,can include arithmetic or string operations or even other
  2496. function calls. Argument expressions are evaluated from left to right.
  2497.  
  2498. Functions can also be invoked using the CALL instruction. The syntax of this
  2499. form is slightly different,and is described in Chapter 4. The CALL instruction
  2500. can be used to invoke a function that may not return a value.
  2501.  
  2502. SEARCH ORDER
  2503.  
  2504. Function linkages in ARexx are established dynamically at the time of the
  2505. function call. A specific search order is followed until a function matching
  2506. the name symbol or string is found. If the specified function cannot be
  2507. located, an error is generated and the expression evaluation is terminated. The
  2508. full search order is:
  2509.  
  2510. 1. Internal Functions. The program source is examined for a label that matches
  2511. the function name. If a match is found,a new storage environment is created and
  2512. control is transferred to the label.
  2513.  
  2514. 2. Built-In Functions. The Build-In function library is searched for the
  2515. specified name. All of these functions are defined by uppercase names,and the
  2516. library has been specially organized to make the search as efficient as
  2517. possible.
  2518.  
  2519.                 47
  2520.  
  2521. 3. Function Libraries and Function Hosts. The available function libraries and
  2522. function hosts are maintained in a prioritized list,which is searched starting
  2523. at the highest priority until the requested function is found or the end of the
  2524. list is reached. Each function library is opened and called at a special entry
  2525. point to determine whether it contains a function matching the given name.
  2526. Function hosts are called using a message-passing protocol similar to that used
  2527. for commands,and may be used as gateways for remote procedure calls to other
  2528. machines in a network.
  2529.  
  2530. 4. External ARexx Programs. The final search step is to check for an external
  2531. ARexx program file by sending an invocation message to the ARexx resident
  2532. process. The search always begins in the current directory,and follows the same
  2533. search path as the original ARexx program invocation. The name matching process
  2534. is not case-sensitive.
  2535.  
  2536. Note that the function name-matching procedure may be case-sensitive for some
  2537. of the search steps but not for others. The matching procedure used in a
  2538. function library or function host is left to the discretion of the applications
  2539. designer. Functions defined with mixed-case names must be called using a string
  2540. token,since symbol names are always translated to uppercase.
  2541.  
  2542. The full search order is followed whenever the function name is defined by a
  2543. symbol token. However,the search for internal functions is bypassed if the name
  2544. is specified by a string token. This allows internal functions to usurp the
  2545. names of external functions,as in the following example:
  2546.  
  2547. CENTER:                /* internal "CENTER" */
  2548. arg string,length        /* get arguments     */
  2549. length = min(length,60)        /* compute length    */
  2550. return 'CENTER'(string,length)
  2551.  
  2552. Here the Built-In fuction CENTER()has been replaced by an internal function of
  2553. the same name,which calls the original function after modifying the length
  2554. argument.
  2555.  
  2556. INTERNAL FUNCTIONS
  2557.  
  2558. The interpreter creates a new storage environment when an internal function is
  2559. called,so that the previous(caller's)environment is preserved. The new
  2560. environment inherits the values from its predecessor,but subsequent changes to
  2561. the environment variables do not affect the previous environment. The specific
  2562. values that are preserved are:
  2563.  
  2564. The current and previous host addresses,
  2565. The NUMERIC DIGITS,FUZZ,and FORM settings,
  2566. The trace option,inhibit flag,and interace flag,
  2567. The state of the interrupt flags defined by the SIGNAL instruction,and
  2568. The current prompt string as set by the OPTIONS PROMPT instruction.
  2569.  
  2570. The new environment does not automatically get a new symbol table,so initially
  2571. all of the variables in the previous environment are available to the called
  2572. function. The PROCEDURE instruction can be used to create a new symbol table
  2573.  
  2574.                 48
  2575.  
  2576. and thereby protect the caller's symbol values.
  2577.  
  2578. Execution of the internal function proceeds until a RETURN instruction is
  2579. executed. At this point the new environment is dismantled and control resumes
  2580. at the point of the function call. The expression supplied with the RETURN
  2581. instruction is evaluated and passed back to the caller as the fuction result.
  2582.  
  2583. BUILT-IN FUNCTIONS
  2584.  
  2585. ARexx provides a substantial library of predefined functions as part of the
  2586. language system. These functions are always available and have been optimized
  2587. to work with the internal data structures. In general the Built-In functions
  2588. execute much faster than an equivalent interpreted function,so their usage is
  2589. strongly recommended.
  2590.  
  2591. The Built-In Function Library is not user-extensible,but additional functions
  2592. will be included in later releases.
  2593.  
  2594. EXTERNAL FUNCTION LIBRARIES
  2595.  
  2596. External function libraries provide a mechanism with which users and
  2597. applications developers can extend the functionality of ARexx. A function
  2598. library is a collection of one or more functions together with a "query" entry
  2599. point that serves to match a name string with the appropriate function.
  2600. External function libraries are supported as standard Amiga shared libraries,
  2601. and may be either memory or disk-resident. Disk-resident libraries are loaded
  2602. and opened as needed.
  2603.  
  2604. The ARexx resident process maintains a list,called the Library List,of the
  2605. currently available function libraries and function hosts. Applications
  2606. programs can add or remove function libraries as required. The Library List is
  2607. maintained as a priority-sorted queue,and entries can be added at an
  2608. appropriate priority to control the function name resolution. Libraries with
  2609. higher priorities are searched first;within a given priority level,those
  2610. libraries added first are searched first.
  2611.  
  2612. During the search process the ARexx interpreter opens each library and calls
  2613. its "query" entry point. The query function must then check to see whether the
  2614. requested function name is in the library. If not,it returns a "function not
  2615. found" error code and the search continues with the next library in the list.
  2616. Function libraries are always closed after being checked so that the operatiing
  2617. system can reclaim the memory space if required. Once the requested function
  2618. has been found,it is called with the arguments passed by the interpreter,and
  2619. must return an error code and a result string.
  2620.  
  2621. The ARexx language system includes an external function library in a file
  2622. called "rexxsupport.library". It contains a number of Amiga-specific functions
  2623. and is described in Appendix D. Chapter 10 provides information on designing
  2624. and implementing function libraries.
  2625.  
  2626.                 49
  2627.  
  2628. FUNCTION HOSTS
  2629.  
  2630. Function hosts are called by sending a function invocation message packet to
  2631. the public message port identified by the host's name. No constraints are
  2632. imposed on the iternal design of the host except that it must eventually return
  2633. the invocation message with an appropriate return code and result string. The
  2634. function call may result in a new program being loaded and run,or might even be
  2635. sent to a network handler as a remote procedure call.
  2636.  
  2637. The available function hosts,along with the function libraries,are contained in
  2638. the Library List maintained by the resident process. This list provides a
  2639. general mechanism for resolving function names in a priority-controlled manner.
  2640.  
  2641. The ARexx resident process is an example of a function host. It is added to the
  2642. Library List at a nominal priority of -60 when the resident process is started,
  2643. using the same name ("REXX")that is used for command invocations. When it
  2644. receives a function invocation packet,it searches for an external file matching
  2645. the function name,just as it would for a command invocation of the same name.
  2646. In particular,the search begins with the current directory and process is not
  2647. case-sensitive,but is affected by the presence of explicit directory
  2648. specifications or file extensions in the name string. The rules governing the
  2649. search for external programs are covered in Chapter 9.
  2650.  
  2651. External programs are always run as a separate process in the Amiga's
  2652. multitasking system. The calling program "sleeps" until the called function
  2653. finishes and the message packet returns. The result string and error code are
  2654. returned in the packet.
  2655.  
  2656. 6-2 THE BUILT-IN FUNCTION LIBRARY
  2657.  
  2658. This section of the chapter is devoted to descriptions of the individual Built
  2659. In functions,which are listed alphabetically. Many of the functions have
  2660. optional as well as required arguments. The optional arguments are shown in
  2661. brackets,and generally have a default value that is used if the argument is
  2662. omitted.
  2663.  
  2664. MAXIMUM ARGUMENTS. While internal functions can be called with any number of
  2665. arguments,the Built-In functions(and external functions as well)are limited to
  2666. a maximum of 15 arguments.
  2667.  
  2668. PAD AND OPTION CHARACTERS. For functions that accept a "pad" character
  2669. argument,only the first character of the argument string is significant. If a
  2670. null string is supplied,the default padding character(usually a blank)will be
  2671. used. Similarly,where an option keyword is specified as an argument,only the
  2672. first character is significant. Option keywords may be given in uppercase or
  2673. lowercase.
  2674.  
  2675. I/O SUPPORT FUNCTIONS. ARexx provides functions for creating and manipulating
  2676. external DOS files. The functions available at the present time are OPEN(),
  2677. CLOSE(),READCH(),READLN(),WRITECH(),WRITELN(),EOF(),SEEK(),and EXISTS(). Files
  2678. are referenced by a "logical name," a case-sensitive name that is assigned to a
  2679. file when it is first opened.
  2680.  
  2681.                 50
  2682.  
  2683. There is no limit to the number of files that may be open simultaneously,and
  2684. all open files are closed automatically when the program exits.
  2685.  
  2686. BIT-MANIPULATION FUNCTIONS. The functions BITCHG(),BITCLR(),BITCOMP(),BITSET(),
  2687. and BITTST() are provided to implement extended bit-testing on character
  2688. strings. These functions differ from similar string-manipulation functions in
  2689. that the elementary unit of comparison is the bit rather than the byte. Bit
  2690. number are defined such that bit 0 is the low-order bit of the rightmost byte
  2691. of the string.
  2692.  
  2693. ABBREV()
  2694.  
  2695. Usage:ABBREV(string1,string2,[length]
  2696. Returns a boolean value that indicates whether string2 is an abbreviation of
  2697. string1 with length greater than or equal to the specified length argument. The
  2698. default length is 0,so the null string is an acceptable abbreviation.
  2699. Example:
  2700.  
  2701.     say abbrev('fullname','ful'  ==>1
  2702.     say abbrev('almost','alm',4) ==>0
  2703.     say abbrev('any','')         ==>1
  2704.  
  2705. ABS()
  2706.  
  2707. Usage:ABS(number)
  2708. Returns the absolute value of the number argument,which must be numeric.
  2709. Examples:
  2710.  
  2711.     say abs(-5.35)            ==>5.35
  2712.     say abs(10)            ==>10
  2713.  
  2714. ADDLIB()
  2715.  
  2716. Usage ADDLIB(name,priority,[offset,version])
  2717. Adds a function library or a function host to the Library List maintained by
  2718. the resident process. The name argument specifies either the name of a function
  2719. library or the public message port associated with a function host. The name is
  2720. case-sensitive,and any libraries thus declared should reside in the system
  2721. LIBS: directory. The priority argument specifies the search priority and must
  2722. be an integer between 100 and -100,inclusive. The offset and version arguments
  2723. apply only to libraries. The offset is the integer offset to the library's
  2724. "query" entry point,and the version is an integer specifying the minimum
  2725. acceptable release level of the library.
  2726.  
  2727. The function returns a boolean result that indicates whether the operation was
  2728. successful. Note that if a library is specified,it is not actually opened at
  2729. this time;similarly,no check is performed as to whether a specified function
  2730. host port has been opened yet.
  2731. Example:
  2732.  
  2733.     say addlib("rexxsupport.library",0,-30,0)==>1
  2734.     call addlib "EtherNet",-20    /* a gateway */
  2735.  
  2736.                 51
  2737.  
  2738. ADDRESS()
  2739.  
  2740. Usage:ADDRESS()
  2741. Returns the current host address string. The host address is the message port
  2742. to which commands will be sent. The SHOW()function can be used to check whether
  2743. the required external host is actually available.
  2744. See Also:SHOW()
  2745. Example:
  2746.  
  2747.     say address()        ==>REXX
  2748.  
  2749. ARG()
  2750.  
  2751. Usage:ARG([number],['Exists' | 'Omitted'])
  2752. ARG()returns the number of arguments supplied to the current environment. If
  2753. the number parameter alone is supplied,the corresponding argument string is
  2754. returned. If a number and one of the keywords Exists or Omitted is given,the
  2755. boolean return indicates the status of the corresponding argument. Note that
  2756. the existence or omission test does not indicate whether the string has a null
  2757. value,but only whether a string was supplied.
  2758. Examples:
  2759.  
  2760.     /* Assume arguments were: ('one,,10)        */
  2761.     say arg()            ==>3
  2762.     say arg(1)            ==>one
  2763.     say arg(2,'0')            ==>1
  2764.  
  2765. B2C()
  2766.  
  2767. Usage:B2C(string)
  2768. Converts a string of binary digits(0,1)into the corresponding(packed)character
  2769. representation. The conversion is the same as though the argument string had
  2770. been specified as a literal binary string(e.g. '1010'B). Blanks are permitted
  2771. in the string,but only at byte boundaries. This function is particularly useful
  2772. for creating strings that are to be used as bit masks.
  2773. See also:X2C()
  2774. Examples:
  2775.  
  2776.     say b2c('00110011')        ==>3
  2777.     say b2c('01100001')        ==>a
  2778.  
  2779. BITAND()
  2780.  
  2781. Usage:BITAND(string1,string2,[pad])
  2782. The argument strings are logically ANDed together,with the length of the result
  2783. being the longer of the two operand strings. If a pad character is supplied,the
  2784. shorter string is padded on the right;otherwise,the operation terminates at the
  2785. end of the shorter string and the remainder of the longer string is appended to
  2786. the result.
  2787. Example:
  2788.  
  2789.     bitand('0313'x,'FFF0'x)        ==>'0310'x
  2790.  
  2791.                 52
  2792.  
  2793. BITCHG()
  2794. Usage:BITCHG(string,bit)
  2795. Changes the state of the specified bit in the argument string. Bit numbers are
  2796. defined such that bit 0 is the low-order bit of the rightmost byte of the
  2797. string.
  2798. Example:
  2799.     bitchg('0313'x,4)        ==>'0303'x
  2800.  
  2801. BITCLR()
  2802. Usage:BITCLR(string,bit)
  2803. Clears(sets to zero)the specified bit in the argument string. Bit numbers are
  2804. defined such that bit 0 is the low-order bit of the rightmost byte of the
  2805. string.
  2806. Example:
  2807.     bitclr('0313'x,4)        ==>'0303'x
  2808.  
  2809. BITCOMP()
  2810. Usage:BITCOMP(string1,string2,[pad])
  2811. Compares the argument strings bit-by-bit,starting at bit number 0. The returned
  2812. value is the bit number of the first bit in which the strings differ,or -1 if
  2813. the strings are identical.
  2814. Examples:
  2815.     bitcomp('7F'x,'FF'x)        ==>7
  2816.     bitcomp('FF'x,'FF'x)        ==>-1
  2817.  
  2818. BITOR()
  2819. Usage:BITOR(string1,string2,[pad])
  2820. The argument strings are logically ORed together,with the length of the result
  2821. being the longer of the two operand strings. If a pad character is supplied,the
  2822. shorter string is padded on the right;otherwise,the operation terminates at the
  2823. end of the shorter string and the remainder of the longer string is appended to
  2824. the result.
  2825. Example:
  2826.     bitor('0313'x,'003F'x)        ==>'033F'x
  2827.  
  2828. BITSET()
  2829. Usage:BITSET(string,bit)
  2830. Sets the specified bit in the argument string is 1. Bit numbers are defined
  2831. such that bit 0 is the low-order bit of the rightmost byte of the string.
  2832. Example:
  2833.     bitset('0313'x,2)        ==>'0317'x
  2834.  
  2835. BITTST()
  2836. Usage:BITTST(string,bit)
  2837. The boolean return indicates the state of the specified bit in the argument
  2838. string.
  2839.  
  2840.                 53
  2841.  
  2842. Bit numbers are defined such that bit 0 is the low-order bit of the rightmost
  2843. byte to the string.
  2844. Example:
  2845.     bittst('0313'x,4)        ==>1
  2846.  
  2847. BITXOR()
  2848. Usage:BITAND(string1,string2,[pad])
  2849. The argument strings are logically exclusively-ORed together,with the length of
  2850. the result being the longer of the two operand strings. If a pad character is
  2851. supplied,the shorter string is padded on the right;otherwise,the operation
  2852. terminates at the end of the shorter string and the remainder of the longer
  2853. string is appended to the result.
  2854. Example:
  2855.     bitxor('0313'x,'001F'x)        ==>'030C'x
  2856.  
  2857. C2B()
  2858. Usage:C2B(string)
  2859. Converts the character string into the equivalent string of binary digits.
  2860. See Also:C2X()
  2861. Example:
  2862.     say c2b('abc')            ==>011000010110001001100011
  2863.  
  2864. C2D()
  2865. Usage:C2D(string,[n])
  2866. Converts the string argument from its character representation to the
  2867. corresponding decimal number,expressed as ASCII digits(0-9). If n is supplied,
  2868. the character string is considered to be a number expressed in n bytes. The
  2869. string is truncated or padded with nulls on the left as required,and the sign
  2870. bit is extended for the conversion.
  2871. Examples:
  2872.     say c2d('0020'x)        ==>32
  2873.     say c2d('FFFF')            ==>1
  2874.     say c2d('FF0100',x,2)        ==>256
  2875.  
  2876. C2X()
  2877. Usage:C2X(string)
  2878. Converts the string argument from its character representation to the
  2879. corresponding hexadecimal number,expressed as the ACSII characters 0-9 and A-F.
  2880. See Also:C2B()
  2881. Example:
  2882.     say c2x('abc')            ==>616263
  2883.  
  2884.                 54
  2885.  
  2886. CENTER() or CENTRE()
  2887. Usage:CENTER(string,length,[pad])or CENTRE(string,length,[pad])
  2888. Centers the string argument in a string with the specified length. If the
  2889. length is longer than that of the string,pad characters or blanks are added as
  2890. necessary.
  2891. Examples:
  2892.     say center('abc',6)        ==>' abc '
  2893.     say center('abc',6,'+')        ==>'+abc++'
  2894.     say center('123456',3)        ==>'234'
  2895.  
  2896. CLOSE()
  2897. Usage:CLOSE(file)
  2898. Closes the file specified by the given logical name. The returned value is a
  2899. boolean success flag,and will be 1 unless the specified file was not open.
  2900. Example:
  2901.     say close('input')        ==>1
  2902.  
  2903. COMPRESS()
  2904. Usage:COMPRESS(string,[list])
  2905. If the list argument is omitted,the function removes leading,trailing,or
  2906. embedded blank characters from the string argument. If the optional list is
  2907. supplied,it specifies the characters to be removed from the string.
  2908. Examples:
  2909.     say compress (' why not ')    ==>whynot
  2910.     say compress ('++12-34-+','+-') ==>1234
  2911.  
  2912. COMPARE()
  2913. Usage:COMPARE(string1,string2,[pad])
  2914. Compares two strings and returns the index of the first position in which they
  2915. differ,or 0 if the strings are identical. The shorter string is padded as
  2916. required using the supplied character or blanks.
  2917. Examples:
  2918.     say compare('abcde','abcce')    ==>4
  2919.     say compare('abcde',abcde')    ==>0
  2920.     say compare('abc++','abc+-','+') ==>5
  2921.  
  2922. COPIES()
  2923. Usage:COPIES(string,number)
  2924. Creates a new string by concatenating the specified number of copies of the
  2925. original. The number argument may be zero,in which case the null string is
  2926. returned.
  2927.  
  2928.                 55
  2929.  
  2930. Example:
  2931.     say copies('abc',3)        ==>abcabcabc
  2932.  
  2933. D2C()
  2934. Usage:D2C(number)
  2935. Creates a string whose value is the binary(packed)representation of the given
  2936. decimal number.
  2937. Example:
  2938.     d2c(31)                ==>'1F'x
  2939.  
  2940. DATATYPE()
  2941. Usage:DATATYPE9string,[option])
  2942. If the option parameter is not specified,DATATYPE()tests whether the string
  2943. parameter is a valid number and returns either NUM or CHAR. If an option
  2944. keyword is given,the boolean return indicates whether the string satisfied the
  2945. requested test. The following option keywords are recognized:
  2946.  
  2947.             Table 6.1 DATATYPE()Options
  2948.  
  2949.     KEYWORD            CHARACTERS ACCEPTED
  2950.     Alphanumeric        Alphabetics (A-Z,a-z)
  2951.                 or Numerics (0-9)
  2952.     Binary            Binary Digits String
  2953.     Lowercase        Lowercase Alphabetics (a-z)
  2954.     Mixed            Mixed Upper/Lowercase
  2955.     Numeric            Valid Numbers
  2956.     Symbol            Valid REXX Symbols
  2957.     Upper            Uppercase Alphabetics (A-Z)
  2958.     Whole            Integer Numbers
  2959.     X            Hex Digits String
  2960. Examples:
  2961.     say datatype('123')            ==>NUM
  2962.     say datatype('1a f2','x')        ==>1
  2963.     say datatype('aBcde','L')        ==>0
  2964.  
  2965. DELSTR()
  2966. Usage:DELSTR(string,n,[length])
  2967. Deletes the substring of the string argument beginning with the nth character
  2968. for the specified length in characters. The default length is the remaining
  2969. length of the string.
  2970. Example:
  2971.     say delstr('123456',2,3)        ==>156
  2972.  
  2973.                 56
  2974.  
  2975. DELWORD()
  2976. Usage:DELWORD(string,n,[length])
  2977. Deletes the substring of the string argument beginning with the nth word for
  2978. the specified length in words. The default length is the remaining length of
  2979. the string. The deleted string includes any trailing blanks following the last
  2980. word.
  2981. Examples:
  2982.     say delword('Tell me a story',2,2)==>'Tell story'
  2983.     say delword('one two three',3)      ==>'one two '
  2984.  
  2985. EOF()
  2986. Usage:EOF(file)
  2987. Checks the specified logical file name and returns the boolean value 1(True)if
  2988. the end-of-file has been reached,and 0(False)otherwise.
  2989. Example:
  2990.     say eof(infile)            ==>1
  2991.  
  2992. ERRORTEXT()
  2993. Usage:ERRORTEXT(n)
  2994. Returns the error message associated with the specified ARexx code. The null
  2995. string is returned if the number is not a valid error code.
  2996. Example:
  2997.     say errortext(41)        ==>Invalid expression
  2998.  
  2999. EXISTS()
  3000. Usage:EXISTS(filename)
  3001. Tests whether an external file of the given filename exists. The name string
  3002. may include device and directory specifications.
  3003. Example:
  3004.     say exists('df0:c/ed')        ==>1
  3005.  
  3006. EXPORT()
  3007. Usage:EXPORT(address,[string],[length],[pad])
  3008. Copies data from the (optional) string into a previously-allocated memory area,
  3009. which must be specified as a 4-byte address. The length parameter specifies the
  3010. maximum number of characters to be copied; the default is the length of the
  3011. string. If the specified length is longer than the string,the remaining area is
  3012. filled with the pad character or nulls('00'x). The returned value is the number
  3013. of characters copied.
  3014.  
  3015. Caution is advised in using this function. Any area of memory can be
  3016. overwritten,possibly causing a system crash. Task switching is forbidden while
  3017. the copy is being done,so system performance may be degraded if long strings
  3018. are copied.
  3019. See Also:IMPORT(),STORAGE()
  3020.  
  3021.                 57
  3022.  
  3023. Example:
  3024.     count = export('0004 0000'x,'The answer')
  3025.  
  3026. FREESPACE()
  3027. Usage:FREESPACE(address,length)
  3028. Returns a block of memory of the given length to the interpreter's internal
  3029. pool. The address argument must be a 4-byte string obtained by a prior call to
  3030. GETSPACE(),the internal allocator. It is not always necessary to release
  3031. internally-allocated memory,since it will be released to the system when the
  3032. program terminates. However,if a very large block has been allocated,returning
  3033. it to the pool may avoid memory space problems. The return value is a boolean
  3034. success flag.
  3035. See Also:GETSPACE()
  3036. Example:
  3037.     say freespace('00042000'x,32)        ==>1
  3038.  
  3039. GETCLIP()
  3040. Usage:GETCLIP(name)
  3041. Searches the Clip List for an entry matching the supplied name parameter,and
  3042. returns the associated value string. The name-matching is case-sensitive,and
  3043. the null string is returned if the name cannot be found. The usage and
  3044. maintenance of Clip List entries is described in the Chapter 9.
  3045. See Also:SETCLIP()
  3046. Example:
  3047.     /* Assume 'numbers' contains 'PI=3.14159'    */
  3048.     say getclip('numbers')        ==>PI=3.14159
  3049.  
  3050. GETSPACE()
  3051. Usage:GETSPACE(length)
  3052. Allocates a block of memory of the specified length from the interpreter's
  3053. internal pool. The returned value is the 4-byte address of the allocated block,
  3054. which is not cleared or otherwise initialized. Internal memory is automatically
  3055. returned to the system when the ARexx program terminates,so this function
  3056. should not be used to allocate memory for use by external programs. The Support
  3057. Library(described in Appendix D)includes the function ALLOCMEM()which to
  3058. allocate memory from the system free list.
  3059. See Also:FREESPACE()
  3060. Example:
  3061.     say c2x(getspace(32))        ==>'0003BF40'x
  3062.  
  3063. HASH()
  3064. Usage:HASH(string)
  3065. Returns the hash attribute of a string as a decimal number,and updates the
  3066. internal hash value of the string.
  3067.  
  3068.                 58
  3069.  
  3070. Example:
  3071.     say hash('1')            ==>49
  3072.  
  3073. IMPORT()
  3074. Usage:IMPORT(address,[length])
  3075. Creates a string by copying data from the specified 4-byte address. If the
  3076. length parameter is not supplied,the copy terminates when a null byte is found.
  3077. See Also:EXPORT()
  3078. Example:
  3079.     extval = import('0004 0000'x,8)
  3080.  
  3081. INDEX()
  3082. Usage:INDEX(string,pattern,[start])
  3083. Searches for the first occurrence of the pattern argument in the string
  3084. argument,beginning at the specified start position. The default start position
  3085. is 1. The returned value is the index of the matched pattern,or 0 if the
  3086. pattern was not found.
  3087. Examples:
  3088.     say index("123456","23")    ==>2
  3089.     say index("123456","77")    ==>0
  3090.     say index("123123","23",3)    ==>5
  3091.  
  3092. INSERT()
  3093. Usage:INSERT(new,old,[start],[length],[pad])
  3094. Inserts the new string into the old string after the specified start position.
  3095. The default starting position is 0. The new string is truncated or padded to
  3096. the specified length as required,using the supplied pad character or blanks. If
  3097. the start position is beyond the end of the old string,the old string is padded
  3098. on the right.
  3099. Examples:
  3100.     say insert('ab,'12345')        ==>ab12345
  3101.     say insert('123','++',3,5,'-')    ==>++-123--
  3102.  
  3103. LASTPOS()
  3104. Usage:LASTPOS(pattern,string,[start])
  3105. Searches backwards for the first occurrence of the pattern argument in the
  3106. string argument,beginning at the specified start position. The default starting
  3107. position is the end of the string. The returned value is the index of the
  3108. matched pattern,or 0 if the pattern was not found.
  3109.  
  3110.                 59
  3111.  
  3112. Examples:
  3113.     say lastpos("123234","2")    ==>4
  3114.     say lastpos("123234","5")    ==>0
  3115.     say lastpos("123234","2",3)    ==>2
  3116.  
  3117. LEFT()
  3118. Usage:LEFT(string,length,[pad])
  3119. Returns the leftmost substring in the given string argument with the specified
  3120. length. If the substring is shorter than the requested length,it is padded on
  3121. the left with the supplied pad character or blanks.
  3122. Examples:
  3123.     say left('123456',3)        ==>123
  3124.     say left('123456',8,'+')    ==>123456++
  3125.  
  3126. LENGTH()
  3127. Usage:LENGTH(string)
  3128. Returns the length of the string.
  3129. Example:
  3130.     say length('three')        ==>5
  3131.  
  3132. MAX()
  3133. Usage:MAX(number,number[,number,...])
  3134. Returns the maximum of the supplied arguments,all of which must be numeric. At
  3135. least two parameters must be supplied.
  3136. Example:
  3137.     say max(2.1,3,-1_        ==>3
  3138.  
  3139. MIN()
  3140. Usage:MIN(number,number[,number,...])
  3141. Returns the minimum of the supplied arguments,all of which must be numeric. At
  3142. least two parameters must be supplied.
  3143. Example:
  3144.     say min(2.1,3,-1)        ==>-1
  3145.  
  3146. OPEN()
  3147. Usage:OPEN(file,filename,['Append' | 'Read' | 'Write'])
  3148. Opens an external file for the specified operation. The file argument defines
  3149. the logical name by which the file will be referenced. The filename is the
  3150. external name of the file,and may include device and directory specifications.
  3151. The function returns a boolean value that indicates whether the operation was
  3152. successful. There is no limit to the number of files that can be open
  3153.  
  3154.                 60
  3155.  
  3156. simultaneusly,and all open files are closed automatically when the program
  3157. exits.
  3158. See Also:CLOSE(),READ(),WRITE()
  3159. Examples:
  3160.     say open('MyCon','CON:160/50/320/100/MyCon/cds') ==>1
  3161.     say open('outfile','ram:temp','W')         ==>1
  3162.  
  3163. OVERLAY()
  3164. Usage:OVERLAY(new,old,[start],[length],[pad])
  3165. Overlays the new string onto the old string beginning at the specified start
  3166. position,which must be positive. The default starting position is 1. The new
  3167. string is truncated or padded to the specified length as required,using the
  3168. supplied pad character or blanks. If the start position is beyond the end of
  3169. the old string,the old string is padded on the right.
  3170. Examples:
  3171.     say overlay('bb,'abcd')            ==>bbcd
  3172.     say overlay('4','123',5,5,'-')        ==>123--4----
  3173.  
  3174. POS()
  3175. Usage:POS(pattern,string,[start])
  3176. Searches for the first occurrence of the pattern argument in the string
  3177. argument,beginning at the position specified by the start argument. The default
  3178. starting position is 1. The returned value is the index of the matched
  3179. string,or 0 if the pattern wasn't found.
  3180. Examples:
  3181.     say pos('23','123234')            ==>2
  3182.     say pos('77','123234')            ==>0
  3183.     say pos('23','123234',3)        ==>4
  3184.  
  3185. PRAGMA()
  3186. Usage:PRAGMA(option,[value])
  3187. This function allows a program to change various attributes relating to the
  3188. system environment within which the program executes. The option argument is a
  3189. keyword that specifies an environmental attribute;the currently implemented
  3190. options are Directory and Priority. The value argument supplies the new
  3191. attribute value to be installed. The value returned by the function depends on
  3192. the attribute selected. Some attributes return the previous value
  3193. installed,while others may simply set a boolean success flag. The currently
  3194. defined option keywords are listed below.
  3195.  
  3196. DIRECTORY. Specifies a new "current" directory. The current directory is used
  3197. as the "root" for filenames that do not explicitly include a device
  3198. specification. The return value is a boolean success flag.
  3199.  
  3200. PRIORITY. Specifies a new task priority. The priority value must be an integer
  3201. in the range -128 to 127,but the practical range is much more limited. ARexx
  3202. programs should never be run at a priority higher than that of the resident
  3203. process,which currently runs at priority 4. The returned value is the previous
  3204. priority level.
  3205.  
  3206.                 61
  3207.  
  3208. Examples:
  3209.     say pragma('priority',-5)        ==>0
  3210.     call pragma 'Directory','df0:system'
  3211.  
  3212. RANDOM()
  3213. Usage:RANDOM([min],[max],[seed])
  3214. Returns a pseudorandom integer in the interval specified by the min and max
  3215. arguments. The default minimum value is 0 and the default maximum value is 999.
  3216. The interval max-min must be less than or equal to 1000. If a greater range of
  3217. random integers is required,the values from the RANDU()function can be suitable
  3218. scaled and translated.
  3219.  
  3220. The seed argument can be supplied to initialize the internal state of the
  3221. random number generator.
  3222. See Also:RANDU()
  3223. Example:
  3224.     thisroll = random(1,6)    /* might be 1    */
  3225.     nextroll = random(1,6)    /* snake eyes?    */
  3226.  
  3227. RANDU()
  3228. Usage:RANDU([seed])
  3229. Returns a uniformly-distributed pseudorandom number between 0 and 1. The number
  3230. of digits of precision in the result is always equal to the current Numeric
  3231. Digits setting. With the choice of suitable scaling and translation values,
  3232. RANDU()can be used to generate pseudorandom numbers on an arbitrary interval.
  3233.  
  3234. The optional seed argument is used to initialize the internal state of the
  3235. random number generator.
  3236. See Also:RANDOM()
  3237. Example:
  3238.     firsttry = randu()    /* 0.371902021? */
  3239.     numeric digits 3
  3240.     tryagain = randu()    /* 0.873?    */
  3241.  
  3242. READCH()
  3243. Usage:READCH(file,length)
  3244. Reads the specified number of characters from the given logical file into a
  3245. string. The length of the returned string is the actual number of characters
  3246. read,and may be less than the requested length if,for example,the end-of-file
  3247. was reached.
  3248. See Also:READLN()
  3249. Example:
  3250.     instring = readch('input',10)
  3251.  
  3252.                 62
  3253.  
  3254. READLN()
  3255. Usage:READLN(file)
  3256. Reads characters from the given logical file into a string until a "newline"
  3257. character is found. The returned string does not include the "newline".
  3258. See Also:READCH()
  3259. Examples:
  3260.     instring = readln('MyFile')
  3261.  
  3262. REMLIB()
  3263. Usage:REMLIB(name)
  3264. Removes an entry with the given name from the Library List maintained by the
  3265. resident process. The boolean return is 1 if the entry was found and
  3266. successfully removed. Note that this function does not make a distinction
  3267. between function libraries and function hosts,but simply removes a named entry.
  3268. See Also:ADDLIB()
  3269. Example:
  3270.     say remlib('MyLibrary.library')==>1
  3271.  
  3272. REVERSE()
  3273. Usage:REVERSE(string)
  3274. Reverses the sequence of characters in the string.
  3275. Example:
  3276.     say reverse('?ton yhw')        ==>why not?
  3277.  
  3278. RIGHT()
  3279. Usage:RIGHT(string,length,[pad])
  3280. Returns the rightmost substring in the given string argument with the specified
  3281. length. If the substring is shorter than the requested length,it is padded on
  3282. the left with the supplied pad character or blanks.
  3283. Examples:
  3284.     say right('123456',4)        ==>3456
  3285.     say right('123456',8,'+')    ==>++123456
  3286.  
  3287. SEEK()
  3288. Usage:SEEK(file,offset,['Begin' | 'Current' | 'End'])
  3289. Moves to a new position in the given logical file,specified as an offset from
  3290. an anchor position. The default anchor is Current. The returned value is the
  3291. new position relative to the start of the file.
  3292. Examples:
  3293.     say seek('input',10,'B')    ==>10
  3294.     say seek('input',O,'E')        ==>356  /* file length    */
  3295.  
  3296.                 63
  3297.  
  3298. SETCLIP()
  3299. Usage:SETCLIP(name,[value])
  3300. Adds a name-value pair to the Clip List maintained by the resident process. If
  3301. an entry of the same name already exists,its value is updated to the supplied
  3302. value string. Entries may be removed by specifying a null value. The function
  3303. returns a boolean value that indicates whether the operation was successful.
  3304. Examples:
  3305.     say setclip('path','df0:s')    ==>1
  3306.     say setclip('path')        ==>1
  3307.  
  3308. SHOW()
  3309. Usage:SHOW(option,[name],[pad])
  3310. Returns the names in the resource list specified by the option argument,or
  3311. tests to see whether an entry with the specified name is available. The
  3312. currently implemented options keywords are Clip,Files,Libraries,and Ports,
  3313. which are described below.
  3314.  
  3315. Clip. Examines the names in the Clip List.
  3316. Files. Examines the names of the currently open logical file names.
  3317. Libraries. Examines the names in the Library List,which are either function
  3318. libraries or function hosts.
  3319. Ports. Examine the names in the system Ports List.
  3320.  
  3321. If the name argument is omitted,the function returns a string with the resource
  3322. names separated by a blank space or the pad character,if one was supplied. If
  3323. the name argument is given,the returned boolean value indicates whether the
  3324. name was found in the resource list. The name entries are case-sensitive.
  3325.  
  3326. SIGN()
  3327. Usage:SIGN(number)
  3328. Returns 1 if the number argument is positive or zero,and -1 if number is
  3329. negative. The argument must be numeric.
  3330. Examples:
  3331.     say sign(12)            ==>1
  3332.     say sign(-33)            ==>-1
  3333.  
  3334. SPACE()
  3335. Usage:SPACE(string,n,[pad])
  3336. Reformats the string argument so that there are n spaces(blank characters)
  3337. between each pair of words. If the pad character is specified,it is used
  3338. instead of blanks as the separator character. Specifying n as 0 will remove all
  3339. blanks from the string.
  3340. Examples:
  3341.     say space('Now is the time',3)    ==>'Now   is   the   time'
  3342.     say space('Now is the time',0)    ==>'Nowisthetime'
  3343.     say space('1 2 3',1,'+')    ==>'1+2+3'
  3344.  
  3345.                 64
  3346.  
  3347. STORAGE()
  3348. Usage:STORAGE([address],[string],[length],[pad])
  3349. Calling STORAGE()with no arguments returns the available system memory. If the
  3350. address argument is given,it must be a 4-byte string,and the function copies
  3351. data from the(optional)string into the indicated memory area. The length
  3352. parameter specifies the maximum number of bytes to be copied,and defaults to
  3353. the length of the string. If the specified length is longer than the string,the
  3354. remaining area is filled with the pad character or nulls('00'x.)
  3355.  
  3356. The returned value is the previous contents of the memory area. This can be
  3357. used in a subsequent call to restore the original contents.
  3358.  
  3359. Caution is advised in using this function. Any area of memory can be
  3360. overwritten,possibly causing a system crash. Task switching is forbidden while
  3361. the copy is being done,so system performance may be degraded if long strings
  3362. are copied.
  3363. See Also:EXPORT()
  3364. Examples:
  3365.     say storage()            ==>248400
  3366.     oldval = storage('0004 000'x,'The answer')
  3367.     call storage '0004 0000'x,,32,'+'
  3368.  
  3369. STRIP()
  3370. Usage:STRIP(string,[{'B' | 'L' | 'T'}],[pad])
  3371. If neither of the optional parameters is supplied,the function removes both
  3372. leading and trailing blanks from the string argument. The second argument
  3373. specifies whether Leading,Trailing,or Both(leading and trailing)characters are
  3374. to be removed. The optional pad(or unpad,perhaps)argument selects the character
  3375. to be removed.
  3376. Examples:
  3377.     say strip(' say what? ')        ==>'say what?'
  3378.     say strip(' say what? ','L')        ==>'say what? '
  3379.     say strip('++123+++','B','+')        ==>'123'
  3380.  
  3381. SUBSTR()
  3382. Usage:SUBSTR(string,start,[length],[pad])
  3383. Returns the substring of the string argument beginning at the specified start
  3384. position for the specified length. The starting position must be positive,and
  3385. the default length is the remaining length of the string. If the substring is
  3386. shorter than the requested length,it is padded on the left with the blanks or
  3387. the specified pad character.
  3388. Examples:
  3389.     say substr('23456',4,2)        ==>45
  3390.     say substr('myname',3,6,'=')    ==>name==
  3391.  
  3392.                 65
  3393.  
  3394. SUBWORD()
  3395. Usage:SUBWORD(string,n,[length])
  3396. Returns the substring of the string argument beginning with the nth word for
  3397. the specified length in words. The default length is the remaining length of
  3398. the string. The returned string will never have leading or trailing blanks.
  3399. Example:
  3400.     say subword('Now is the time ',2,2)    ==>is the
  3401.  
  3402. SYMBOL()
  3403. Usage:SYMBOL(name)
  3404. Tests whether the name argument is a valid REXX symbol. If the name is not a
  3405. valid symbol,the function returns the string BAD. Otherwise,the returned string
  3406. is LIT if the symbol is uninitialized and VAR if it has been assigned a value.
  3407. Examples:
  3408.     say symbol('J')            ==>VAR
  3409.     say symbol('x')            ==>LIT
  3410.     say symbol('++')        -->BAD
  3411.  
  3412. TIME()
  3413. Usage:TIME(option)
  3414. Returns the current system time or controls the internal elapsed time counter.
  3415. The valid option keywords are listed below.
  3416.  
  3417.             Table 6.2 TIME()Options
  3418.     
  3419.     OPTION KEYWORD        DESCRIPTION
  3420.     Elapsed            Elapsed time in seconds.
  3421.     Hours            Current time in hours since midnight
  3422.     Minutes            Current time in minutes since midnight
  3423.     Reset            Reset the elapsed time clock
  3424.     Seconds            Current time in seconds since midnight
  3425.  
  3426. If no option is specified,the function returns the current system time in the
  3427. form HH:MM:SS.
  3428. Examples:
  3429.     /* Suppose that the time is 1:02 AM ...        */
  3430.     say time('Hours')        ==>1
  3431.     say time('m')            ==>62
  3432.     say time('S')            ==>3720
  3433.     call time 'R'            /* reset timer    */
  3434.     say time('E')            ==>.020
  3435.  
  3436.                 66
  3437.  
  3438. TRACE()
  3439. Usage:TRACE(option)
  3440. Sets the tracing mode to that specified by the option keyword,which must be one
  3441. of the valid alphabetic or prefix options. The tracing options are described in
  3442. Chapter 7. The TRACE()function will alter the tracing mode even during
  3443. interactive tracing,when TRACE instructions in the source program are ignored.
  3444. The returned value is the mode in effect before the function call;this allows
  3445. the previous trace mode to be restored later.
  3446. Example:
  3447.     /* Assume tracing mode is ?AL        */
  3448.     say trace('Results')        ==>?A
  3449.  
  3450. TRANSLATE()
  3451. Usage:TRANSLATE(string,[output],[input],[pad])
  3452. This function constructs a translation table and uses it to replace selected
  3453. characters in the argument string. If only the string argument is given,it is
  3454. translated to uppercase. If an input table is supplied,it modifies the
  3455. translation table so that characters in the argument string that occur in the
  3456. input table are replaced with the corresponding character in the output table.
  3457. Characters beyond the end of the output table are replaced with the specified
  3458. pad character or a blank.
  3459.  
  3460. Note that the result string is always of the same length as the original
  3461. string. The input and output tables may be of any length.
  3462. Examples:
  3463.     say translate("abcde","123","cbade","+")    ==>321++
  3464.     say translate("low")                ==>LOW
  3465.     say translate("0110","10","01")            ==>1001
  3466.  
  3467. TRIM()
  3468. Usage:TRIM(string)
  3469. Removes trailing blanks from the string argument.
  3470. Example:
  3471.     say length(trim(' abc  '))    ==>4
  3472.     
  3473. UPPER()
  3474. Usage:UPPER(string)
  3475. Translates the strip to uppercase. The action of this function is equivalent to
  3476. that of TRANSLATE(string),but it is slightly faster for short strings.
  3477. Example:
  3478.     say upper('One Fine Day')    ==>ONE FINE DAY
  3479.  
  3480.                 67
  3481.  
  3482. VALUE()
  3483. Usage:VALUE(name)
  3484. Returns the value of the symbol represented by the name argument.
  3485. Example:
  3486.     /* Assume that J has the value of 12        */
  3487.     say value('j')            ==>12
  3488.  
  3489. VERIFY()
  3490. Usage:VERIFY(string,list,['Match'])
  3491. If the Match argument is omitted,the function returns the index of the first
  3492. character in the string argument which is not contained in the list argument,or
  3493. 0 if all of the characters are in the list. If the Match keyword is supplied,
  3494. the function returns the index of the first character which is in the list,or 0
  3495. if none of the characters are.
  3496. Examples:
  3497.     say verify('123456','0123456789')    ==>0
  3498.     say verify('123a56','0123456789')    ==>4
  3499.     say verify('123a45','abcdefghij','m')    ==>4
  3500.  
  3501. WORD()
  3502. Usage:WORD(string,n)
  3503. Returns the nth word in the string argument,or the null string if there are
  3504. fewer than n words.
  3505. Example:
  3506.     say word('Now is the time ',2)        ==>is
  3507.  
  3508. WORDINDEX()
  3509. Usage:WORINDEX(string,n)
  3510. Returns the starting position of the nth word in the argument string,or 0 if
  3511. there are fewer than n words.
  3512. Example:
  3513.     say wordindex('Now is the time ',3)    ==>8
  3514.  
  3515. WORDLENGTH()
  3516. Usage:WORDLENGTH(string,n)
  3517. Returns the length of the nth word in the string argument.
  3518. Example:
  3519.     say wordlength('one two three',3)    ==>5
  3520.  
  3521.                 68
  3522.  
  3523. WORDS()
  3524. Usage:WORDS(string)
  3525. Returns the number of words in the string argument.
  3526. Example:
  3527.     say words("You don't say!")        ==>3
  3528.  
  3529. WRITECH()
  3530. Usage:WRITECH(file,string)
  3531. Writes the string argument to the given logical file. The returned value is the
  3532. actual number of characters written.
  3533. Example:
  3534.     say writech('output','Testing')        ==>7
  3535.  
  3536. WRITELN()
  3537. Usage:WRITELN(file,string)
  3538. Writes the string argument to the given logical file with a "newline" appended.
  3539. The returned value is the actual number of characters written.
  3540. Example:
  3541.     say writeln('output','Testing')        ==>8
  3542.  
  3543. X2C()
  3544. Usage:X2C(string)
  3545. Converts a string of hex digits into the(packed)character representation. Blank
  3546. characters are permitted in the argument string at byte boundaries.
  3547. Examples:
  3548.     say x2c('12ab')                ==>'12ab'x
  3549.     say x2c('12 ab')            ==>'12ab'x
  3550.  
  3551. XRANGE()
  3552. Usage:XRANGE([start],[end])
  3553. Generates a string consisting of all characters numerically between the
  3554. specified start and end values. The default start character is '00'x,and the
  3555. default end character is 'FF'x. Only the first character of the start and end
  3556. arguments is significant.
  3557. Examples:
  3558.     say xrange()            ==>'00010203 ... FDFEFF'x
  3559.     say xrange('a','f')        ==>'abcdef'
  3560.     say xrange(,'10'x)        ==>'00010203040506070809010'x
  3561.  
  3562.                 69
  3563.  
  3564.               NOW LOAD PART 2
  3565.  
  3566. end.
  3567.